B. Applejack and Storages

网友投稿 581 2022-10-18

B. Applejack and Storages

B. Applejack and Storages

// Problem: B. Applejack and Storages// Contest: Codeforces - Codeforces Round #662 (Div. 2)// URL: Memory Limit: 256 MB// Time Limit: 2000 ms// 2022-02-26 13:04:35// // Powered by CP Editor (namespace std;#define rep(i,l,r) for(int i=(l);i<=(r);i++)#define per(i,l,r) for(int i=(l);i>=(r);i--)#define ll long long#define pii pair#define mset(s,t) memset(s,t,sizeof(t))#define mcpy(s,t) memcpy(s,t,sizeof(t))#define fi first#define se second#define pb push_back#define all(x) (x).begin(),(x).end()#define SZ(x) ((int)(x).size())#define mp make_pairconst ll mod = 1e9 + 7;inline ll qmi (ll a, ll b) { ll ans = 1; while (b) { if (b & 1) ans = ans * a%mod; a = a * a %mod; b >>= 1; } return ans;}inline int read () { int x = 0, f = 0; char ch = getchar(); while (!isdigit(ch)) f |= (ch=='-'),ch= getchar(); while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); return f?-x:x;}template void print(T x) { if (x < 0) putchar('-'), x = -x; if (x >= 10) print(x/10); putchar(x % 10 + '0');}inline ll sub (ll a, ll b) { return ((a - b ) %mod + mod) %mod;}inline ll add (ll a, ll b) { return (a + b) %mod;}inline ll inv (ll a) { return qmi(a, mod - 2);}int cnt[100005];void solve() { int n; cin >> n; int q; int cnt2 = 0, cnt4 = 0; for (int i =1; i <= n; i ++) { int t; cin >> t; cnt2 -= cnt[t] / 2; cnt4 -= cnt[t] / 4; cnt[t] ++; cnt2 += cnt[t] / 2; cnt4 += cnt[t] / 4; } cin >> q; while (q --) { int x; string op; cin >> op >> x; cnt2 -= cnt[x] / 2; cnt4 -= cnt[x] / 4; if (op == "-") { cnt[x] --; } else { cnt[x] ++; } cnt2 += cnt[x] / 2; cnt4 += cnt[x] / 4; if (cnt4 >= 1 && cnt2 >= 4) cout << "YES" << '\n'; else cout << "NO" << '\n'; }}int main () { int t; t =1; //cin >> t; while (t --) solve(); return 0;}

分两类看,数量超过2的和数量超过4的,然后看贡献。对于每一次改变,都要先减去原先的,然乎加上新的。这是个常用的思想

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:SpringBoot整合oceanbase,实现oracle无缝切换到oceanbase
下一篇:CaptureMock- Python 模拟测试框架
相关文章

 发表评论

暂时没有评论,来抢沙发吧~