結果
問題 | No.2311 [Cherry 5th Tune] Cherry Month |
ユーザー | 👑 potato167 |
提出日時 | 2023-05-19 22:57:07 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 495 ms / 4,600 ms |
コード長 | 4,254 bytes |
コンパイル時間 | 3,230 ms |
コンパイル使用メモリ | 225,192 KB |
実行使用メモリ | 53,120 KB |
最終ジャッジ日時 | 2024-05-10 06:22:18 |
合計ジャッジ時間 | 24,325 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 313 ms
44,160 KB |
testcase_03 | AC | 129 ms
17,284 KB |
testcase_04 | AC | 138 ms
20,872 KB |
testcase_05 | AC | 137 ms
20,992 KB |
testcase_06 | AC | 173 ms
27,204 KB |
testcase_07 | AC | 134 ms
16,640 KB |
testcase_08 | AC | 271 ms
35,840 KB |
testcase_09 | AC | 237 ms
33,536 KB |
testcase_10 | AC | 199 ms
30,592 KB |
testcase_11 | AC | 247 ms
31,744 KB |
testcase_12 | AC | 329 ms
34,252 KB |
testcase_13 | AC | 313 ms
30,464 KB |
testcase_14 | AC | 244 ms
43,392 KB |
testcase_15 | AC | 303 ms
39,552 KB |
testcase_16 | AC | 159 ms
33,456 KB |
testcase_17 | AC | 284 ms
42,752 KB |
testcase_18 | AC | 241 ms
41,984 KB |
testcase_19 | AC | 288 ms
40,832 KB |
testcase_20 | AC | 292 ms
28,876 KB |
testcase_21 | AC | 254 ms
28,572 KB |
testcase_22 | AC | 244 ms
32,156 KB |
testcase_23 | AC | 311 ms
34,048 KB |
testcase_24 | AC | 302 ms
30,112 KB |
testcase_25 | AC | 186 ms
40,960 KB |
testcase_26 | AC | 350 ms
37,684 KB |
testcase_27 | AC | 300 ms
48,000 KB |
testcase_28 | AC | 306 ms
48,000 KB |
testcase_29 | AC | 306 ms
48,000 KB |
testcase_30 | AC | 183 ms
35,156 KB |
testcase_31 | AC | 183 ms
35,248 KB |
testcase_32 | AC | 184 ms
35,328 KB |
testcase_33 | AC | 300 ms
47,616 KB |
testcase_34 | AC | 275 ms
47,488 KB |
testcase_35 | AC | 290 ms
47,488 KB |
testcase_36 | AC | 348 ms
47,560 KB |
testcase_37 | AC | 351 ms
47,616 KB |
testcase_38 | AC | 358 ms
47,704 KB |
testcase_39 | AC | 409 ms
48,384 KB |
testcase_40 | AC | 398 ms
48,084 KB |
testcase_41 | AC | 401 ms
48,512 KB |
testcase_42 | AC | 395 ms
47,872 KB |
testcase_43 | AC | 428 ms
49,060 KB |
testcase_44 | AC | 359 ms
53,044 KB |
testcase_45 | AC | 357 ms
52,992 KB |
testcase_46 | AC | 284 ms
39,828 KB |
testcase_47 | AC | 495 ms
53,120 KB |
testcase_48 | AC | 331 ms
50,304 KB |
testcase_49 | AC | 351 ms
50,432 KB |
testcase_50 | AC | 357 ms
50,408 KB |
ソースコード
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") using namespace std; using std::cout; using std::cin; using std::endl; using ll=long long; using ld=long double; ll ILL=2167167167167167167; const int INF=2100000000; const int mod=998244353; #define rep(i,a,b) for (ll i=a;i<b;i++) #define all(p) p.begin(),p.end() template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>; template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();} template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();} template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;} template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;} template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());} template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});} void yneos(bool a){if(a) cout<<"Yes\n"; else cout<<"No\n";} template<class T> void vec_out(vector<T> &p){for(int i=0;i<(int)(p.size());i++){if(i) cout<<" ";cout<<p[i];}cout<<"\n";} template<class T> T vec_min(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmin(ans,x);return ans;} template<class T> T vec_max(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmax(ans,x);return ans;} template<class T> T vec_sum(vector<T> &a){assert(!a.empty());T ans=a[0]-a[0];for(auto &x:a) ans+=x;return ans;} int pop_count(long long a){int res=0;while(a){res+=(a&1),a>>=1;}return res;} namespace po167{ struct UFtree_yuki_2311 { using _F=int; int _n; vector<ll> val1,val2; vector<vector<int>> q; int component; UFtree_yuki_2311(int n):_n(n),val1(n),val2(n),q(n),component(n),par(n){ for(int i=0;i<n;i++){ par[i]=i; q[i]={i}; val1[i]=0; val2[i]=0; } } //根っこを返す int root(int a){ assert(0<=a&&a<_n); if(a==par[a]) return a; return par[a]=root(par[a]); } //trueなら1,falseなら0 int same(int a,int b){ assert(0<=a&&a<_n); assert(0<=b&&b<_n); if(root(a)==root(b)) return 1; else return 0; } //a,bが違う根っこの元なら結合する,結合したらtrueを返す bool unite(int a,int b){ a=root(a),b=root(b); if(a==b) return false; if(q[a].size()<q[b].size()) std::swap(a,b); //merge for(auto x:q[b]){ q[a].push_back(x); val2[x]=val1[a]-calc(x); } par[b]=a; component--; return true; } void fall(int v,ll K){ assert(0<=v&&v<_n); val1[root(v)]+=K; } ll calc(int v){ assert(0<=v&&v<_n); return val1[root(v)]-val2[v]; } private: std::vector<int> par; }; } void solve(); // oddloop int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t=1; //cin>>t; rep(i,0,t) solve(); } void solve(){ int N; cin>>N; vector<ll> A(N); rep(i,0,N) cin>>A[i]; ll T; cin>>T; vector ev(T,vector<ll>(3)); rep(i,0,T){ rep(j,0,3) cin>>ev[i][j]; ev[i][1]--; if(ev[i][0]==1) ev[i][2]--; } vector<vector<int>> H(T); ll Q; cin>>Q; vector<ll> ans(Q); vector<ll> S(Q),I(Q); rep(i,0,Q){ cin>>S[i]>>I[i]; S[i]--,I[i]--; if(S[i]!=-1) H[S[i]].push_back(i); } // 2 and 3 { vector<int> large(N); int B=444; rep(i,0,T){ if(ev[i][0]==1) large[ev[i][1]]++,large[ev[i][2]]++; } rep(i,0,N) if(large[i]<B) large[i]=0; vector<ll> v1(N),v2(N); vector<vector<int>> g1(N),g2(N); rep(i,0,T){ if(ev[i][0]==1){ if(large[ev[i][2]]){ g2[ev[i][1]].push_back(ev[i][2]); } else{ g1[ev[i][2]].push_back(ev[i][1]); } if(large[ev[i][1]]){ g2[ev[i][2]].push_back(ev[i][1]); } else{ g1[ev[i][1]].push_back(ev[i][2]); } } if(ev[i][0]==2){ v2[ev[i][1]]+=ev[i][2]; } if(ev[i][0]==3){ v2[ev[i][1]]+=ev[i][2]; if(large[ev[i][1]]){ v1[ev[i][1]]+=ev[i][2]; } else{ for(auto x:g1[ev[i][1]]){ v2[x]+=ev[i][2]; } } } for(auto x:H[i]){ ans[x]+=v2[I[x]]; for(auto y:g2[I[x]]) ans[x]+=v1[y]; } } } // 4 { po167::UFtree_yuki_2311 uft(N); rep(i,0,T){ if(ev[i][0]==1) uft.unite(ev[i][1],ev[i][2]); if(ev[i][0]==4) uft.fall(ev[i][1],ev[i][2]); for(auto x:H[i]){ ans[x]+=uft.calc(I[x]); } } } rep(i,0,Q){ cout<<max(0ll,A[I[i]]-ans[i])<<"\n"; } }