Submission #3441573


Source Code Expand

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N (1<<18)

int a[(2 * N)];

void init(void){
	f(i, 2 * N)a[i] = -MOD;
	return;
}


void change(int k, int x){
	k += N - 1;
	if(a[k]<x)a[k] = x;
else return;
	while (k > 1){
		k = k / 2;
		a[k] = max(a[2 * k], a[2 * k + 1]);
	}
	return;
}
//探索(0<=l<r<=n)範囲は(l<=x<r)初期は(l,r,1,0,N)
int max_search(int l, int r, int k, int sl, int sr){
	if (r <= sl || sr <= l)return -MOD;
	else if (l <= sl&&sr <= r) return a[k];
	else{
		int vl = max_search(l, r, 2 * k, sl, (sl + sr) / 2);
		int vr = max_search(l, r, 2 * k + 1, (sl + sr) / 2, sr);
		return max(vl, vr);
	}
}




int main(void){
int b[N];
int s[N];
vector<int>q[N];
int n;
int m;
int x,y,z;
init();
scanf("%d",&n);
b[0]=0;
s[0]=b[0];
f(i,n){
scanf("%d",&x);
if(x==0){
b[i+1]=b[i]+1;
s[i+1]=b[i+1];
}
else{
b[i+1]=b[i];
s[i+1]=b[i+1];
}
}
scanf("%d",&m);
f(i,m){
scanf("%d %d",&x,&y);
q[x].push_back(y);
}
for(int i=1;i<=n;i++){
if(b[i-1]<b[i]){
s[i]=max(s[i-1]+1,s[i]);
}

f(j,q[i].size()){
x=s[i-1]+(q[i][j]-b[q[i][j]])-(i-1-b[i-1]);
y=max_search(i,q[i][j]+1,1,0,N);
if(y>(-MOD)){
y+=(q[i][j]-b[q[i][j]]);
z=max(x,y);
}
else z=x;
s[q[i][j]]=max(s[q[i][j]],z);
change(q[i][j],z-(q[i][j]-b[q[i][j]]));
}

}
printf("%d\n",n-s[n]);


return 0;
}

Submission Info

Submission Time
Task F - NRE
User ptrs
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1584 Byte
Status WA
Exec Time 162 ms
Memory 13952 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:57:15: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
 scanf("%d",&n);
               ^
./Main.cpp:61:15: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
 scanf("%d",&x);
               ^
./Main.cpp:71:15: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
 scanf("%d",&m);
               ^
./Main.cpp:73:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
 scanf("%d %d",&x,&y);
                     ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 1000
Status
AC × 7
AC × 16
WA × 111
Set Name Test Cases
Sample example_0, example_1, example_2, example_3, example_4, example_5, example_6
All cent_0, cent_1, cent_2, cent_3, cent_4, cent_5, cent_6, cent_7, cent_8, cent_9, example_0, example_1, example_2, example_3, example_4, example_5, example_6, full_0, full_1, full_10, full_11, full_12, full_13, full_14, full_15, full_16, full_17, full_18, full_19, full_2, full_3, full_4, full_5, full_6, full_7, full_8, full_9, maxrand_0, maxrand_1, maxrand_10, maxrand_11, maxrand_12, maxrand_13, maxrand_14, maxrand_15, maxrand_16, maxrand_17, maxrand_18, maxrand_19, maxrand_2, maxrand_20, maxrand_21, maxrand_22, maxrand_23, maxrand_24, maxrand_25, maxrand_26, maxrand_27, maxrand_28, maxrand_29, maxrand_3, maxrand_4, maxrand_5, maxrand_6, maxrand_7, maxrand_8, maxrand_9, rand_0, rand_1, rand_10, rand_11, rand_12, rand_13, rand_14, rand_15, rand_16, rand_17, rand_18, rand_19, rand_2, rand_3, rand_4, rand_5, rand_6, rand_7, rand_8, rand_9, small_0, small_1, small_2, small_3, small_4, small_5, small_6, small_7, small_8, small_9, smallwidth_0, smallwidth_1, smallwidth_10, smallwidth_11, smallwidth_12, smallwidth_13, smallwidth_14, smallwidth_15, smallwidth_16, smallwidth_17, smallwidth_18, smallwidth_19, smallwidth_2, smallwidth_20, smallwidth_21, smallwidth_22, smallwidth_23, smallwidth_24, smallwidth_25, smallwidth_26, smallwidth_27, smallwidth_28, smallwidth_29, smallwidth_3, smallwidth_4, smallwidth_5, smallwidth_6, smallwidth_7, smallwidth_8, smallwidth_9
Case Name Status Exec Time Memory
cent_0 WA 141 ms 12668 KB
cent_1 WA 151 ms 13440 KB
cent_2 WA 136 ms 12408 KB
cent_3 WA 146 ms 12924 KB
cent_4 WA 147 ms 13180 KB
cent_5 WA 137 ms 12536 KB
cent_6 WA 144 ms 12920 KB
cent_7 WA 143 ms 12536 KB
cent_8 WA 151 ms 13568 KB
cent_9 WA 135 ms 12664 KB
example_0 AC 4 ms 8448 KB
example_1 AC 4 ms 8448 KB
example_2 AC 4 ms 8448 KB
example_3 AC 4 ms 8448 KB
example_4 AC 4 ms 8448 KB
example_5 AC 4 ms 8448 KB
example_6 AC 4 ms 8448 KB
full_0 WA 22 ms 9984 KB
full_1 WA 145 ms 13824 KB
full_10 WA 22 ms 9984 KB
full_11 WA 145 ms 13824 KB
full_12 WA 22 ms 10112 KB
full_13 WA 145 ms 13824 KB
full_14 WA 22 ms 9984 KB
full_15 WA 145 ms 13824 KB
full_16 WA 22 ms 9984 KB
full_17 WA 145 ms 13824 KB
full_18 WA 22 ms 10112 KB
full_19 WA 144 ms 13824 KB
full_2 WA 22 ms 10112 KB
full_3 WA 145 ms 13824 KB
full_4 WA 22 ms 9984 KB
full_5 WA 145 ms 13824 KB
full_6 WA 21 ms 9984 KB
full_7 WA 145 ms 13824 KB
full_8 WA 21 ms 9984 KB
full_9 WA 144 ms 13824 KB
maxrand_0 WA 22 ms 9984 KB
maxrand_1 WA 155 ms 13568 KB
maxrand_10 WA 22 ms 9984 KB
maxrand_11 WA 153 ms 13568 KB
maxrand_12 WA 23 ms 10112 KB
maxrand_13 WA 162 ms 13568 KB
maxrand_14 WA 22 ms 9984 KB
maxrand_15 WA 157 ms 13568 KB
maxrand_16 WA 22 ms 9984 KB
maxrand_17 WA 153 ms 13568 KB
maxrand_18 WA 23 ms 10112 KB
maxrand_19 WA 154 ms 13568 KB
maxrand_2 WA 22 ms 9984 KB
maxrand_20 WA 22 ms 9984 KB
maxrand_21 WA 155 ms 13568 KB
maxrand_22 WA 23 ms 10112 KB
maxrand_23 WA 153 ms 13568 KB
maxrand_24 WA 23 ms 10112 KB
maxrand_25 WA 153 ms 13568 KB
maxrand_26 WA 22 ms 10112 KB
maxrand_27 WA 153 ms 13568 KB
maxrand_28 WA 22 ms 9984 KB
maxrand_29 WA 152 ms 13568 KB
maxrand_3 WA 153 ms 13568 KB
maxrand_4 WA 22 ms 9984 KB
maxrand_5 WA 153 ms 13568 KB
maxrand_6 WA 22 ms 9984 KB
maxrand_7 WA 152 ms 13568 KB
maxrand_8 WA 22 ms 9984 KB
maxrand_9 WA 153 ms 13568 KB
rand_0 WA 152 ms 13568 KB
rand_1 WA 87 ms 10496 KB
rand_10 WA 153 ms 13568 KB
rand_11 WA 53 ms 10752 KB
rand_12 WA 152 ms 13568 KB
rand_13 WA 112 ms 12032 KB
rand_14 WA 153 ms 13568 KB
rand_15 WA 70 ms 9984 KB
rand_16 WA 152 ms 13568 KB
rand_17 WA 86 ms 11008 KB
rand_18 WA 153 ms 13568 KB
rand_19 WA 133 ms 13056 KB
rand_2 WA 153 ms 13568 KB
rand_3 WA 121 ms 10752 KB
rand_4 WA 152 ms 13568 KB
rand_5 WA 79 ms 9600 KB
rand_6 WA 153 ms 13568 KB
rand_7 WA 96 ms 10880 KB
rand_8 WA 152 ms 13568 KB
rand_9 WA 32 ms 10240 KB
small_0 AC 4 ms 8448 KB
small_1 AC 4 ms 8448 KB
small_2 AC 4 ms 8448 KB
small_3 WA 4 ms 8448 KB
small_4 AC 4 ms 8448 KB
small_5 AC 4 ms 8448 KB
small_6 AC 4 ms 8448 KB
small_7 AC 4 ms 8448 KB
small_8 AC 4 ms 8448 KB
small_9 AC 4 ms 8448 KB
smallwidth_0 WA 22 ms 9984 KB
smallwidth_1 WA 138 ms 13952 KB
smallwidth_10 WA 22 ms 9984 KB
smallwidth_11 WA 121 ms 13952 KB
smallwidth_12 WA 22 ms 9984 KB
smallwidth_13 WA 138 ms 13952 KB
smallwidth_14 WA 22 ms 9984 KB
smallwidth_15 WA 121 ms 13952 KB
smallwidth_16 WA 22 ms 9984 KB
smallwidth_17 WA 138 ms 13952 KB
smallwidth_18 WA 22 ms 9984 KB
smallwidth_19 WA 121 ms 13952 KB
smallwidth_2 WA 23 ms 10112 KB
smallwidth_20 WA 22 ms 9984 KB
smallwidth_21 WA 138 ms 13952 KB
smallwidth_22 WA 22 ms 9984 KB
smallwidth_23 WA 123 ms 13952 KB
smallwidth_24 WA 22 ms 9984 KB
smallwidth_25 WA 138 ms 13952 KB
smallwidth_26 WA 22 ms 9984 KB
smallwidth_27 WA 121 ms 13952 KB
smallwidth_28 WA 22 ms 9984 KB
smallwidth_29 WA 138 ms 13952 KB
smallwidth_3 WA 121 ms 13952 KB
smallwidth_4 WA 22 ms 9984 KB
smallwidth_5 WA 137 ms 13952 KB
smallwidth_6 WA 22 ms 9984 KB
smallwidth_7 WA 122 ms 13952 KB
smallwidth_8 WA 22 ms 9984 KB
smallwidth_9 WA 138 ms 13952 KB