結果

問題 No.2223 Merged Med
ユーザー 沙耶花沙耶花
提出日時 2023-02-17 22:22:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,637 bytes
コンパイル時間 4,317 ms
コンパイル使用メモリ 265,360 KB
実行使用メモリ 14,464 KB
最終ジャッジ日時 2023-09-26 19:38:44
合計ジャッジ時間 23,082 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 WA -
testcase_06 AC 2 ms
4,376 KB
testcase_07 WA -
testcase_08 AC 2 ms
4,380 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 2 ms
4,380 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 680 ms
14,128 KB
testcase_31 AC 449 ms
12,744 KB
testcase_32 AC 107 ms
4,492 KB
testcase_33 WA -
testcase_34 AC 821 ms
14,464 KB
testcase_35 AC 602 ms
12,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 1000000000000000001

struct D{
	long long pre= 0,suf = 0,all = 0,ma = 0;
};

D op(D a,D b){
	D c;
	c.all = a.all + b.all;
	c.pre = min(a.pre,a.all + b.pre);
	c.suf = min(b.suf,b.all + a.suf);
	
	c.ma = min({a.ma,b.ma,c.all,c.pre,c.suf});
	return c;
}

D e(){
	return D();
}

int main(){
	
	int n,q;
	cin>>n>>q;
	vector<int> a(n);
	vector<vector<int>> is(n+5);
	rep(i,n){
		cin>>a[i];
		is[a[i]].push_back(i);
	}
	vector<int> l(q),r(q);
	rep(i,q){
		cin>>l[i]>>r[i];
		l[i]--;
	}
	
	vector<int> ok(q,n),ng(q,0);
	rep(_,18){
		vector<vector<int>> qs(n+1);
		rep(i,q){
			qs[(ok[i]+ng[i])/2].push_back(i);
		}
		fenwick_tree<int> F(n);
		segtree<D,op,e> seg(n);
		rep(i,n){
			F.add(i,-1);
			D t;
			t.all = -1;
			t.suf = -1;
			t.pre = -1;
			t.ma = -1;
			seg.set(i,t);
		}
		rep(i,n){
			rep(j,is[i].size()){
				int ii = is[i][j];
				F.add(ii,2);
				D t;
				t.all = 1;
				seg.set(ii,t);
			}
			rep(j,qs[i].size()){
				int ii = qs[i][j];
				bool f=  false;
				if(F.sum(l[ii],r[ii])>0)f = true;
				else{
					
					long long s= F.sum(l[ii],r[ii]);
					/*if(ii==0 && i==0){
						cout<<s<<',';
					}
					*/
					s -= seg.prod(l[ii],r[ii]).ma;
					s --;
					/*
					if(ii==0 && i==0){
						cout<<s<<endl;
					}
					*/
					if(s>0)f = true;
				}
				
				if(f)ok[ii] = (ok[ii]+ng[ii])/2;
				else ng[ii] = (ok[ii]+ng[ii])/2;
				
			}
		}
	}
	rep(i,q){
		cout<<ok[i]<<endl;
	}
	
	return 0;
}
0