結果

問題 No.956 Number of Unbalanced
ユーザー 👑 kmjpkmjp
提出日時 2019-12-19 00:19:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,612 bytes
コンパイル時間 1,554 ms
コンパイル使用メモリ 169,628 KB
実行使用メモリ 10,860 KB
最終ジャッジ日時 2023-09-21 04:28:31
合計ジャッジ時間 16,833 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,104 KB
testcase_01 AC 3 ms
6,180 KB
testcase_02 AC 3 ms
6,124 KB
testcase_03 AC 3 ms
6,176 KB
testcase_04 WA -
testcase_05 AC 3 ms
6,124 KB
testcase_06 WA -
testcase_07 AC 247 ms
7,428 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 230 ms
7,156 KB
testcase_11 AC 535 ms
10,860 KB
testcase_12 WA -
testcase_13 AC 205 ms
9,232 KB
testcase_14 AC 295 ms
8,496 KB
testcase_15 AC 211 ms
8,812 KB
testcase_16 WA -
testcase_17 AC 209 ms
8,888 KB
testcase_18 AC 295 ms
8,780 KB
testcase_19 AC 211 ms
9,520 KB
testcase_20 AC 297 ms
8,736 KB
testcase_21 AC 206 ms
9,212 KB
testcase_22 AC 210 ms
9,004 KB
testcase_23 WA -
testcase_24 AC 210 ms
9,128 KB
testcase_25 TLE -
testcase_26 TLE -
testcase_27 TLE -
testcase_28 TLE -
testcase_29 AC 294 ms
8,492 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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];
vector<int> E[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,20> bt;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) {
		cin>>A[i];
		E[A[i]].push_back(i);
	}
	
	ll ret=0;
	FOR(x,N) {
		int ma=0;
		FOR(i,500) if(x+i<=N) {
			if(E[A[x+i]].size()<250) {
				C[A[x+i]]++;
				ma=max(ma,C[A[x+i]]);
			}
			if(ma*2>i+1) ret++;
		}
		FOR(i,500) if(x+i<=N && E[A[x+i]].size()<250) C[A[x+i]]--;
	}
	
	FOR(i,100100) if(E[i].size()>=250) {
		int cur=111111;
		bt.add(cur,1);
		FOR(x,N) {
			if(A[x]==i) cur++;
			else cur--;
			ret+=bt(cur-1);
			bt.add(cur,1);
		}
		cur=111111;
		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;
}
0