結果
問題 | 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
|
実行時間 | 512 ms / 4,600 ms |
コード長 | 4,254 bytes |
コンパイル時間 | 3,610 ms |
コンパイル使用メモリ | 225,316 KB |
実行使用メモリ | 53,056 KB |
最終ジャッジ日時 | 2024-12-20 01:31:59 |
合計ジャッジ時間 | 26,711 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,820 KB |
testcase_02 | AC | 441 ms
44,248 KB |
testcase_03 | AC | 136 ms
17,284 KB |
testcase_04 | AC | 139 ms
20,772 KB |
testcase_05 | AC | 131 ms
20,952 KB |
testcase_06 | AC | 169 ms
27,060 KB |
testcase_07 | AC | 136 ms
16,512 KB |
testcase_08 | AC | 269 ms
35,900 KB |
testcase_09 | AC | 220 ms
33,560 KB |
testcase_10 | AC | 185 ms
30,436 KB |
testcase_11 | AC | 290 ms
31,728 KB |
testcase_12 | AC | 289 ms
34,228 KB |
testcase_13 | AC | 283 ms
30,348 KB |
testcase_14 | AC | 238 ms
43,360 KB |
testcase_15 | AC | 269 ms
39,488 KB |
testcase_16 | AC | 153 ms
33,524 KB |
testcase_17 | AC | 278 ms
42,776 KB |
testcase_18 | AC | 286 ms
41,980 KB |
testcase_19 | AC | 272 ms
40,876 KB |
testcase_20 | AC | 293 ms
28,860 KB |
testcase_21 | AC | 261 ms
28,528 KB |
testcase_22 | AC | 242 ms
32,068 KB |
testcase_23 | AC | 297 ms
34,036 KB |
testcase_24 | AC | 289 ms
30,268 KB |
testcase_25 | AC | 180 ms
40,956 KB |
testcase_26 | AC | 349 ms
37,548 KB |
testcase_27 | AC | 298 ms
47,932 KB |
testcase_28 | AC | 313 ms
47,960 KB |
testcase_29 | AC | 299 ms
47,968 KB |
testcase_30 | AC | 180 ms
35,328 KB |
testcase_31 | AC | 187 ms
35,344 KB |
testcase_32 | AC | 186 ms
35,164 KB |
testcase_33 | AC | 279 ms
47,560 KB |
testcase_34 | AC | 285 ms
47,472 KB |
testcase_35 | AC | 288 ms
47,424 KB |
testcase_36 | AC | 344 ms
47,600 KB |
testcase_37 | AC | 361 ms
47,560 KB |
testcase_38 | AC | 380 ms
47,500 KB |
testcase_39 | AC | 412 ms
48,276 KB |
testcase_40 | AC | 383 ms
47,956 KB |
testcase_41 | AC | 410 ms
48,388 KB |
testcase_42 | AC | 354 ms
47,848 KB |
testcase_43 | AC | 388 ms
49,016 KB |
testcase_44 | AC | 344 ms
52,992 KB |
testcase_45 | AC | 309 ms
52,820 KB |
testcase_46 | AC | 286 ms
39,768 KB |
testcase_47 | AC | 512 ms
53,056 KB |
testcase_48 | AC | 305 ms
50,336 KB |
testcase_49 | AC | 329 ms
50,448 KB |
testcase_50 | AC | 306 ms
50,440 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"; } }