結果
問題 | No.956 Number of Unbalanced |
ユーザー | 👑 kmjp |
提出日時 | 2019-12-19 00:26:05 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 600 ms / 2,000 ms |
コード長 | 1,596 bytes |
コンパイル時間 | 1,549 ms |
コンパイル使用メモリ | 166,680 KB |
実行使用メモリ | 4,892 KB |
最終ジャッジ日時 | 2023-09-21 04:29:45 |
合計ジャッジ時間 | 12,014 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,376 KB |
testcase_01 | AC | 2 ms
4,380 KB |
testcase_02 | AC | 2 ms
4,376 KB |
testcase_03 | AC | 2 ms
4,376 KB |
testcase_04 | AC | 2 ms
4,376 KB |
testcase_05 | AC | 2 ms
4,380 KB |
testcase_06 | AC | 404 ms
4,380 KB |
testcase_07 | AC | 392 ms
4,380 KB |
testcase_08 | AC | 398 ms
4,380 KB |
testcase_09 | AC | 385 ms
4,380 KB |
testcase_10 | AC | 361 ms
4,376 KB |
testcase_11 | AC | 600 ms
4,892 KB |
testcase_12 | AC | 414 ms
4,440 KB |
testcase_13 | AC | 276 ms
4,380 KB |
testcase_14 | AC | 498 ms
4,568 KB |
testcase_15 | AC | 282 ms
4,376 KB |
testcase_16 | AC | 362 ms
4,376 KB |
testcase_17 | AC | 282 ms
4,376 KB |
testcase_18 | AC | 499 ms
4,696 KB |
testcase_19 | AC | 279 ms
4,380 KB |
testcase_20 | AC | 499 ms
4,800 KB |
testcase_21 | AC | 302 ms
4,840 KB |
testcase_22 | AC | 279 ms
4,376 KB |
testcase_23 | AC | 361 ms
4,380 KB |
testcase_24 | AC | 291 ms
4,376 KB |
testcase_25 | AC | 353 ms
4,380 KB |
testcase_26 | AC | 407 ms
4,376 KB |
testcase_27 | AC | 352 ms
4,376 KB |
testcase_28 | AC | 354 ms
4,380 KB |
testcase_29 | AC | 498 ms
4,588 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[101010]; int num[101010]; int C[101010]; 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<int,18> bt; const int SQ=500; void solve() { int i,j,k,l,r,x,y; string s; cin>>N; FOR(i,N) { cin>>A[i]; num[A[i]]++; } ll ret=0; FOR(x,N) { int ma=0; FOR(i,SQ*2) if(x+i<N) { if(num[A[x+i]]<SQ) { C[A[x+i]]++; ma=max(ma,C[A[x+i]]); } if(ma*2>i+1) ret++; } FOR(i,SQ*2) if(x+i<N && num[A[x+i]]<SQ) C[A[x+i]]--; } FOR(i,100100) if(num[i]>=SQ) { int cur=1<<17; bt.add(cur,1); FOR(x,N) { if(A[x]==i) cur++; else cur--; ret+=bt(cur-1); bt.add(cur,1); } cur=1<<17; bt.add(cur,-1); FOR(x,N) { if(A[x]==i) cur++; else cur--; bt.add(cur,-1); } } 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; }