此文章用于记录codeforces正赛/VP时未AC的题目
1 2 3
| #unfixed https://codeforces.com/contest/2032/problem/D https://codeforces.com/contest/2036/problem/B
|
STL_using
Sort
被sort坑惨了,距离AC只差一个等号
[STL]为什么sort的自定义cmp函数中必须使用严格弱序(strict
weak order)
赛时代码和这份代码只差一个 =
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| #include<cstdio> #include<algorithm> // #define int long long #pragma GCC optimize(2)
using namespace std;
inline int read() { int x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9') { if(ch=='-') f=-1; ch=getchar(); } while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar(); return x*f; }
const int N = 2e5+10; int n , k; struct B { int bin , c; }a[N];
bool cmp( B x , B y ){ return x.c > y.c; }
signed main() { int t = read(); int b , bb; while( t -- ){ n = read() , k = read(); int cnt = 0; int maxn = 0; for(int i = 1;i <= k;i ++){ b = read() , bb = read(); if( a[b].bin == 0 ) cnt ++; a[b].bin ++; a[b].c += bb; maxn = max( maxn , b ); } sort( a + 1 , a + maxn + 1 , cmp ); int ans = 0 , minn = min( cnt , n ); for(int i = 1;i <= minn;i ++){ ans += a[i].c; } printf("%d\n",ans); for(int i = 1;i <= cnt;i ++){ a[i].bin = a[i].c = 0; } } return 0; }
|
Set
使用一个差异数组
来记录,点 是否需要移动
如果出现
s[x] == 'L' && s[x+1] == 'R' && diff[x]
,则这个节点会导致输出
NO
使用set来维护所有不能从 点
移动到点 的点,如果为空则输出
YES
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| #include<iostream> #include<vector> #include<set> #define int long long
using namespace std;
signed main(){ int t;cin >> t;while( t -- ){ int n , q;cin >> n >> q; vector<int> p(n); for(int i = 0;i < n;i ++){cin >> p[i];p[i] --;} vector<int> diff(n);//用于记录差异数组,不等于0则表示需要移动 for(int i = 0;i < n;i ++){ diff[min(i,p[i])] ++; diff[max(i,p[i])] --; } for(int i = 1;i < n;i ++) diff[i] += diff[i-1]; string s;cin >> s; set<int> bad;//用于记录坏节点,即因为这个点则无法YES的 for(int i = 0;i < n;i ++) if( s[i] == 'L' && s[i+1] == 'R' && diff[i] ) bad.insert(i); while( q -- ){ int x;cin >> x;x --;//因为从0开始,所以-1 if( s[x] == 'L' ) s[x] = 'R';//按照题目要求,翻转 else s[x] = 'L'; if( s[x-1] == 'L' && s[x] == 'R' && diff[x-1] ) bad.insert( x - 1 ); else bad.erase( x - 1 ); if( s[x] == 'L' && s[x+1] == 'R' && diff[ x ] ) bad.insert( x ); else bad.erase( x ); if( bad.size() ) cout << "NO" << endl; else cout << "YES" << endl; } } return 0; }
|
MISC
Misunderstand
误认为是数组必须等长划分导致错误
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| #include<iostream> #define int long long using namespace std;
int n , k;
signed main() { ios::sync_with_stdio( false ); int t;cin >> t; while( t -- ){ cin >> n >> k; if( n == 1 ){ cout << "1\n1\n"; continue; } if( k == 1 || k == n ){ cout << "-1\n"; continue; } if( k % 2 ){ cout << 3 << '\n'; cout << "1 " << k-1 << " " << k+2 << '\n'; } else{ cout << 3 << '\n'; cout << "1 " << k << " " << k+1 << '\n'; } } return 0; }
|