CF

Problem - 1980D - Codeforces

计算前缀和后缀,枚举删除元素,如果同时满足前缀,后缀,还有删除之后的不递减就可以了 注意一些边界问题,还有记得提前处理删除边界的情况

#include 
using namespace std;
#define LL long long
//#define double long double
#define endl '\n'
#define ULL unsigned long long
#define PII pair
const LL mod = 998244353;
const int N = 2e5+10;
int a[N], b[N];
bool pre[N], suf[N];void solve()
{int n;cin >> n;for (int i = 1; i <= n;i++){pre[i] = 0;suf[i] = 0;}for (int i = 1; i <= n;i++){cin >> a[i];}for (int i = 1; i < n;i++){b[i] = gcd(a[i], a[i + 1]);}pre[0] = 1;for (int i = 1; i < n;i++){pre[i] = pre[i - 1] & (b[i] >= b[i - 1]);}suf[n - 1] = suf[n] = 1;b[n] = 1e9;//注意for (int i = n - 2; i >= 1;i--){suf[i] = suf[i + 1] & (b[i] <= b[i + 1]);}bool flag = pre[n - 2] || suf[2];//特判边界for (int i = 2; i < n;i++){int x = gcd(a[i - 1], a[i + 1]);if(pre[i-2]&&suf[i+1]&&(b[i-2]<=x&&x<=b[i+1])){flag = 1;break;}}if(flag){cout << "YES\n";}else{cout << "NO\n";}}int main()
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int T;cin >> T;while (T--){solve();}
}

Problem - E - Codeforces

找 \(l,r\) 的最高不相同的位置,构造100000,011111这种形式,然后另一个数字随便选,不要和这两个相等就可以了

#include 
using namespace std;
#define LL long long
//#define double long double
#define endl '\n'
#define ULL unsigned long long
#define PII pair
const LL mod = 998244353;
const int N = 2e5+10;void solve()
{int l, r;cin >> l >> r;int p;for (int i = 30; i >= 0;i--){if((l>>i&1)!=(r>>i&1)){p = i;break;}}int x = (r >> p) << p;int a = x - 1, b = x, c = l;if(c==a){c = r;}// int a, b, c;// cin >> a >> b >> c;cout << a << " " << b << " " << c << endl;//cout << (a ^ b) + (b ^ c) + (a ^ c) << endl;
}int main()
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int T;cin >> T;while (T--){solve();}
}

Problem - 2061D - Codeforces

1600 优先队列 逆向思维,把 b 拆了,b只能拆成 b/2,(b+1)/2,然后判断一下能不能满足a

#include 
using namespace std;
#define LL long long
//#define double long double
#define endl '\n'
#define ULL unsigned long long
#define PII pair
const LL mod = 998244353;
const int N = 2e5+10;
LL a[N];void solve()
{int n, m;cin >> n >> m;LL sum1 = 0, sum2 = 0;for (int i = 1; i <= n;i++){cin >> a[i];sum1 += a[i];}priority_queue q;for (int i = 1; i <= m;i++){LL x;cin >> x;q.push(x);sum2 += x;}if(sum1!=sum2){cout << "No\n";return;}sort(a + 1, a + 1 + n, greater());int pos = 1;while(!q.empty()){if(pos>n||q.size()>n-pos+1){cout << "No\n";return;}LL x = q.top();q.pop();if(x==a[pos]){pos++;}else if(x> T;while (T--){solve();}
}