結果
問題 | No.404 部分門松列 |
ユーザー | 👑 kmjp |
提出日時 | 2021-04-14 23:33:21 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 977 ms / 2,000 ms |
コード長 | 1,901 bytes |
コンパイル時間 | 4,114 ms |
コンパイル使用メモリ | 213,380 KB |
実行使用メモリ | 59,100 KB |
最終ジャッジ日時 | 2023-09-13 13:31:11 |
合計ジャッジ時間 | 19,329 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 6 ms
25,968 KB |
testcase_01 | AC | 6 ms
26,020 KB |
testcase_02 | AC | 6 ms
26,084 KB |
testcase_03 | AC | 6 ms
26,076 KB |
testcase_04 | AC | 6 ms
26,032 KB |
testcase_05 | AC | 6 ms
26,020 KB |
testcase_06 | AC | 7 ms
25,940 KB |
testcase_07 | AC | 6 ms
25,940 KB |
testcase_08 | AC | 6 ms
26,056 KB |
testcase_09 | AC | 6 ms
25,944 KB |
testcase_10 | AC | 6 ms
26,000 KB |
testcase_11 | AC | 6 ms
26,052 KB |
testcase_12 | AC | 7 ms
26,000 KB |
testcase_13 | AC | 418 ms
39,464 KB |
testcase_14 | AC | 446 ms
27,980 KB |
testcase_15 | AC | 354 ms
33,084 KB |
testcase_16 | AC | 438 ms
41,000 KB |
testcase_17 | AC | 640 ms
46,492 KB |
testcase_18 | AC | 316 ms
34,988 KB |
testcase_19 | AC | 215 ms
34,736 KB |
testcase_20 | AC | 454 ms
28,984 KB |
testcase_21 | AC | 580 ms
42,896 KB |
testcase_22 | AC | 400 ms
33,880 KB |
testcase_23 | AC | 504 ms
28,956 KB |
testcase_24 | AC | 638 ms
34,480 KB |
testcase_25 | AC | 977 ms
59,100 KB |
testcase_26 | AC | 883 ms
44,788 KB |
testcase_27 | AC | 272 ms
27,120 KB |
testcase_28 | AC | 527 ms
39,684 KB |
testcase_29 | AC | 678 ms
43,988 KB |
testcase_30 | AC | 464 ms
33,472 KB |
testcase_31 | AC | 154 ms
26,620 KB |
testcase_32 | AC | 599 ms
45,572 KB |
testcase_33 | AC | 613 ms
42,664 KB |
testcase_34 | AC | 551 ms
33,804 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef signed long long ll; #undef _P #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 ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) //------------------------------------------------------- int N; int A[202020]; int Q; int L[202020],R[202020]; ll LU[202020],RU[202020]; ll LD[202020],RD[202020]; template<class V, int ME> class BIT { public: V bit[1<<ME]; V operator()(int e) {if(e<0) return 0;V s=0;e++;while(e) s+=bit[e-1],e-=e&-e; return s;} void add(int e,V v) { e++; while(e<=1<<ME) bit[e-1]+=v,e+=e&-e;} }; BIT<ll,21> LL,RR,ret; vector<int> V; map<ll,ll> sameL,sameR; void solve() { int i,j,k,l,r,x,y; string s; cin>>N; FOR(i,N) cin>>A[i]; cin>>Q; FOR(i,Q) cin>>L[i]>>R[i]; V.push_back(0); V.push_back(1<<30); FOR(i,N) V.push_back(A[i]); FOR(i,Q) V.push_back(L[i]),V.push_back(R[i]); sort(ALL(V)); V.erase(unique(ALL(V)),V.end()); FOR(i,N) { A[i]=lower_bound(ALL(V),A[i])-V.begin(); LU[i]=LL(1<<20)-LL(A[i]); LD[i]=LL(A[i]-1); LL.add(A[i],1); } for(i=N-1;i>=0;i--) { RU[i]=RR(1<<20)-RR(A[i]); RD[i]=RR(A[i]-1); RR.add(A[i],1); ret.add(A[i],LU[i]*RU[i]+LD[i]*RD[i]); } FOR(i,N) sameR[A[i]]++; ll same=0; FOR(i,N) { same -= sameL[A[i]]*sameR[A[i]]; ret.add(A[i],-same); sameR[A[i]]--; sameL[A[i]]++; same += sameL[A[i]]*sameR[A[i]]; } FOR(i,Q) { x=lower_bound(ALL(V),L[i])-V.begin(); y=lower_bound(ALL(V),R[i])-V.begin(); cout<<ret(y)-ret(x-1)<<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); solve(); return 0; }