結果
問題 | No.1788 Same Set |
ユーザー | 👑 kmjp |
提出日時 | 2021-12-18 00:39:11 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 544 ms / 4,000 ms |
コード長 | 2,629 bytes |
コンパイル時間 | 2,461 ms |
コンパイル使用メモリ | 213,172 KB |
実行使用メモリ | 32,716 KB |
最終ジャッジ日時 | 2023-10-13 04:09:18 |
合計ジャッジ時間 | 16,151 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 14 ms
29,740 KB |
testcase_01 | AC | 14 ms
29,760 KB |
testcase_02 | AC | 14 ms
29,620 KB |
testcase_03 | AC | 14 ms
29,552 KB |
testcase_04 | AC | 14 ms
29,628 KB |
testcase_05 | AC | 14 ms
29,624 KB |
testcase_06 | AC | 14 ms
29,544 KB |
testcase_07 | AC | 15 ms
29,724 KB |
testcase_08 | AC | 15 ms
29,628 KB |
testcase_09 | AC | 14 ms
29,724 KB |
testcase_10 | AC | 14 ms
29,784 KB |
testcase_11 | AC | 70 ms
30,328 KB |
testcase_12 | AC | 186 ms
30,272 KB |
testcase_13 | AC | 230 ms
30,268 KB |
testcase_14 | AC | 314 ms
30,256 KB |
testcase_15 | AC | 397 ms
30,324 KB |
testcase_16 | AC | 455 ms
30,352 KB |
testcase_17 | AC | 314 ms
32,224 KB |
testcase_18 | AC | 413 ms
31,296 KB |
testcase_19 | AC | 204 ms
31,148 KB |
testcase_20 | AC | 86 ms
30,900 KB |
testcase_21 | AC | 408 ms
30,824 KB |
testcase_22 | AC | 439 ms
32,268 KB |
testcase_23 | AC | 335 ms
32,220 KB |
testcase_24 | AC | 394 ms
32,332 KB |
testcase_25 | AC | 540 ms
32,312 KB |
testcase_26 | AC | 509 ms
32,272 KB |
testcase_27 | AC | 102 ms
32,336 KB |
testcase_28 | AC | 544 ms
32,568 KB |
testcase_29 | AC | 481 ms
32,304 KB |
testcase_30 | AC | 107 ms
32,468 KB |
testcase_31 | AC | 514 ms
32,244 KB |
testcase_32 | AC | 406 ms
32,716 KB |
testcase_33 | AC | 439 ms
32,268 KB |
testcase_34 | AC | 477 ms
32,200 KB |
testcase_35 | AC | 468 ms
32,200 KB |
testcase_36 | AC | 470 ms
32,320 KB |
testcase_37 | AC | 457 ms
32,196 KB |
testcase_38 | AC | 464 ms
32,560 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef signed long long ll; #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define FORR2(x,y,arr) for(auto& [x,y]:arr) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;} template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;} //------------------------------------------------------- int N; int A[202020]; int B[202020]; int PA[404040]; int PB[404040]; static ll const def=0; template<class V,int NV> class SegTree_3 { public: vector<V> val; vector<pair<V,int>> ma; SegTree_3(){ int i; val.resize(NV*2,0); ma.resize(NV*2); FOR(i,NV) ma[i+NV]={0,1}; for(i=NV-1;i>=1;i--) ma[i]={0,ma[2*i].second+ma[2*i+1].second}; }; pair<V,int> getval(int x,int y,int l=0,int r=NV,int k=1) { if(r<=x || y<=l || y<=x) return {1<<20,0}; if(x<=l && r<=y) return ma[k]; auto a=getval(x,y,l,(l+r)/2,k*2); auto b=getval(x,y,(l+r)/2,r,k*2+1); if(a.first>b.first) swap(a,b); if(a.first==b.first) a.second+=b.second; a.first+=val[k]; return a; } pair<V,int> update(int x,int y, V v,int l=0,int r=NV,int k=1) { if(l>=r||y<=x) return {1<<20,0}; if(x<=l && r<=y) { val[k]+=v; ma[k].first+=v; } else if(l < y && x < r) { auto a=update(x,y,v,l,(l+r)/2,k*2); auto b=update(x,y,v,(l+r)/2,r,k*2+1); if(a.first>b.first) swap(a,b); if(a.first==b.first) a.second+=b.second; a.first+=val[k]; ma[k]=a; } return ma[k]; } }; SegTree_3<int,1<<20> st; void solve() { int i,j,k,l,r,x,y; string s; cin>>N; FOR(i,N) cin>>A[i+1]; FOR(i,N) cin>>B[i+1]; ll ret=0; for(i=1;i<=N;i++) { if(A[i]==B[i]) { x=min(PA[A[i]],PB[B[i]]); y=max(PA[A[i]],PB[B[i]]); st.update(x,y,-1); PA[A[i]]=i; PB[B[i]]=i; } else { x=min(PA[A[i]],PB[A[i]]); y=max(PA[A[i]],PB[A[i]]); st.update(x,y,-1); x=min(PA[B[i]],PB[B[i]]); y=max(PA[B[i]],PB[B[i]]); st.update(x,y,-1); PA[A[i]]=i; PB[B[i]]=i; x=min(PA[A[i]],PB[A[i]]); y=max(PA[A[i]],PB[A[i]]); st.update(x,y,1); x=min(PA[B[i]],PB[B[i]]); y=max(PA[B[i]],PB[B[i]]); st.update(x,y,1); } auto a=st.getval(0,i); if(a.first==0) ret+=a.second; } cout<<ret<<endl; } int main(int argc,char** argv){ string s;int i; if(argc==1) ios::sync_with_stdio(false), cin.tie(0); FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin); cout.tie(0); solve(); return 0; }