A. Era
每个a[i] - i 表示的是当前a[i]前需要插入几个数, 取所有a[i] - i 最大值即可.
#include <iostream> #include <algorithm> using namespace std; typedef long long LL; int main(){ int t; cin >> t; while(t--) { int n, x; cin >> n; int res = 0; for(int i = 1; i <= n; i ++) { cin >> x; res = max(res, x-i); } cout << res <<endl; } return 0; }
B. XOR Specia-LIS-t
位运算思维
如果n是偶数的话,可以分成n个序列, 那么偶数个1异或之后必然为0。
那么如果n是奇数, 如果存在一组a[i] <= a[i-1], 将其归为一组, 则n-1个1异或后也必然为0
#include <iostream> #include <algorithm> using namespace std; typedef long long LL; const int N = 1e5 + 10; int a[N]; int main(){ int t; cin >> t; while(t--) { int n; cin >> n; for (int i = 1; i <= n; i ++ ) cin >> a[i]; if(n % 2 == 0) { cout << "YES" << endl; continue; } bool flag = false; for (int i = 2; i <= n; i ++ ) if(a[i] <= a[i - 1]) //注意有=号 { flag = true; break; } if(flag) cout << "YES" << endl; else cout << "NO" << endl; } return 0; }
C. Di-visible Confusion
我们可以选择从后往前看这个序列, 这样每删除一个数会尽量不影响其他的数字, 对于每次操作分两种情况:
1. 可以删去a[i]%(i+1) != 0, 没有操作
2. 否则, 如果取余2~i 都为0, 那么这个数算是删不了了, 注定结果失败
只要不失败就成功.
#include <iostream> #include <algorithm> using namespace std; typedef long long LL; const int N = 1e5 + 10; int a[N]; int main(){ int t; cin >> t; while(t--) { int n; cin >> n; bool res_ok = 1; for(int i = 1; i <= n; i ++) cin >> a[i]; for(int i = n; i >= 1; -- i) { if(a[i]%(i+1) == 0) { int flag = 0; for(int j = i; j > 1; -- j) if(a[i] % j != 0) { flag = 1; break; } if(!flag) res_ok = 0; } } if(!res_ok) puts("NO"); else puts("YES"); } return 0; }