結果
問題 | No.1526 Sum of Mex 2 |
ユーザー | 👑 kmjp |
提出日時 | 2021-05-31 23:09:46 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 89 ms / 3,000 ms |
コード長 | 1,693 bytes |
コンパイル時間 | 2,374 ms |
コンパイル使用メモリ | 209,248 KB |
実行使用メモリ | 24,820 KB |
最終ジャッジ日時 | 2024-04-26 09:38:43 |
合計ジャッジ時間 | 5,015 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 5 ms
12,932 KB |
testcase_01 | AC | 6 ms
12,800 KB |
testcase_02 | AC | 6 ms
12,928 KB |
testcase_03 | AC | 7 ms
12,928 KB |
testcase_04 | AC | 6 ms
13,056 KB |
testcase_05 | AC | 6 ms
13,056 KB |
testcase_06 | AC | 6 ms
13,184 KB |
testcase_07 | AC | 6 ms
13,056 KB |
testcase_08 | AC | 6 ms
13,184 KB |
testcase_09 | AC | 6 ms
12,928 KB |
testcase_10 | AC | 5 ms
12,960 KB |
testcase_11 | AC | 6 ms
13,056 KB |
testcase_12 | AC | 6 ms
12,928 KB |
testcase_13 | AC | 12 ms
14,464 KB |
testcase_14 | AC | 13 ms
14,464 KB |
testcase_15 | AC | 15 ms
14,976 KB |
testcase_16 | AC | 74 ms
22,144 KB |
testcase_17 | AC | 41 ms
19,360 KB |
testcase_18 | AC | 9 ms
14,080 KB |
testcase_19 | AC | 9 ms
13,696 KB |
testcase_20 | AC | 26 ms
17,008 KB |
testcase_21 | AC | 67 ms
21,888 KB |
testcase_22 | AC | 34 ms
18,304 KB |
testcase_23 | AC | 60 ms
22,100 KB |
testcase_24 | AC | 64 ms
22,400 KB |
testcase_25 | AC | 59 ms
21,784 KB |
testcase_26 | AC | 66 ms
22,144 KB |
testcase_27 | AC | 64 ms
22,324 KB |
testcase_28 | AC | 61 ms
22,528 KB |
testcase_29 | AC | 67 ms
22,388 KB |
testcase_30 | AC | 62 ms
22,656 KB |
testcase_31 | AC | 65 ms
22,528 KB |
testcase_32 | AC | 63 ms
22,032 KB |
testcase_33 | AC | 89 ms
24,820 KB |
evil_largest | RE | - |
ソースコード
#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]; set<int> S[202020]; class AreaRect { map<ll,ll> M; public: ll sum; AreaRect() { M[0]=1LL<<60; M[1LL<<60]=0; sum=0; } void add(ll x,ll y) { auto k=M.lower_bound(x); if(k->second>=y) return; while(prev(M.lower_bound(x))->second<=y) { auto p=*prev(M.lower_bound(x)); M.erase(p.first); sum-=(p.first-prev(M.lower_bound(p.first))->first)*(p.second-M.lower_bound(p.first)->second); } sum += (x-prev(M.lower_bound(x))->first)*(y-M.lower_bound(x)->second); M[x]=y; } }; AreaRect ar; void solve() { int i,j,k,l,r,x,y; string s; cin>>N; FOR(i,N) { cin>>A[i]; S[A[i]].insert(i+1); S[i+1].insert(N+1); } for(i=1;i<=N;i++) { x=*S[i].begin(); ar.add(N+1-i,x); } ll ret=1LL*N*(N+1)/2; FOR(i,N) { ret+=1LL*N*(N+1)-ar.sum; S[A[i]].erase(S[A[i]].begin()); x=*S[A[i]].begin(); ar.add(N+1-A[i],x); } 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; }