Submission #284032

# Submission time Handle Problem Language Result Execution time Memory
284032 2020-08-26T14:06:24 Z AMnu Bubble Sort 2 (JOI18_bubblesort2) C++14
38 / 100
9000 ms 12280 KB
#include "bubblesort2.h"
#include <bits/stdc++.h>
#define pii pair<int,int>
#define i1 first
#define i2 second
using namespace std;

const int INF=1e6+5;

int N, Q;
int T[INF];
vector<int> H;
vector<pii> S;

struct segment {
	int L, R;
	int val, cnt, lazy;
	segment *lef, *rig;
	
	void build(int x,int y) {
		L=x;
		R=y;
		val=-INF;
		cnt=0;
		lazy=0;
		
		if (x==y) {
			return;
		}
		
		int T;
		T=(L+R)/2;
		lef=new segment;
		lef->build(L,T);
		rig=new segment;
		rig->build(T+1,R);
		
		return;
	}
	
	void balance() {
		if (!lazy) {
			return;
		}
		
		lef->val+=lazy;
		lef->lazy+=lazy;
		rig->val+=lazy;
		rig->lazy+=lazy;
		lazy=0;
		
		return;
	}
	
	void update(int x,int y) {
		if (R<x) {
			return;
		}
		
		if (L>=x) {
			val+=y;
			lazy+=y;
			return;
		}
		
		balance();
		lef->update(x,y);
		rig->update(x,y);
		val=max(lef->val,rig->val);
		
		return;
	}
	
	int query(int x) {
		if (L>x) {
			return 0;
		}
		
		if (R<=x) {
			return cnt;
		}
		
		return lef->query(x)+rig->query(x);
	}
	
	void set(int x,int y,int z) {
		if (L==R) {
			val=y;
			cnt=z;
			return;
		}
		
		int T;
		T=(L+R)/2;
		
		if (x<=T) {
			lef->set(x,y,z);
		}
		else {
			rig->set(x,y,z);
		}
		
		cnt=lef->cnt+rig->cnt;
		val=max(lef->val,rig->val);
	}
}
data;

void build(int x,int y) {
	for (int i=x;i<=y;i++) {
		T[i]=-INF;
	}
}

void update(int x,int y) {
	for (int i=x;i<N+Q;i++) {
		T[i]+=y;
	}
}

int query(int x) {
	return data.query(x);
}

int ans() {
	int ret=-INF;
	
	for (int i=0;i<N+Q;i++) {
		ret=max(ret,T[i]);
	}
	
	return ret;
}

void del(pii x) {
	int y=lower_bound(S.begin(),S.end(),x)-S.begin();
	T[y]=-INF;
	data.set(y,0,0);
	update(y+1,1);
}

void add(pii x) {
	int y=lower_bound(S.begin(),S.end(),x)-S.begin();
	T[y]=x.i2-query(y-1);
	data.set(y,0,1);
	update(y+1,-1);
}

vector<int> countScans(vector<int> A,vector<int> X,vector<int> V){
	N=A.size();
	Q=X.size();
	H=vector<int>(Q);
	S=vector<pii>(N+Q);
	
	for (int i=0;i<N;i++) {
		S[i]={A[i],i};
	}
	
	for (int i=0;i<Q;i++) {
		S[i+N]={V[i],X[i]};
	}
	
	sort(S.begin(),S.end());
	build(0,N+Q-1);
	data.build(0,N+Q-1);
	
	for (int i=0;i<N;i++) {
		add({A[i],i});
	}
	
	for (int i=0;i<Q;i++) {
		del({A[X[i]],X[i]});
		A[X[i]]=V[i];
		add({A[X[i]],X[i]});
		H[i]=ans();
	}
	
	return H;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 19 ms 768 KB Output is correct
4 Correct 15 ms 928 KB Output is correct
5 Correct 19 ms 896 KB Output is correct
6 Correct 19 ms 768 KB Output is correct
7 Correct 19 ms 640 KB Output is correct
8 Correct 19 ms 760 KB Output is correct
9 Correct 19 ms 768 KB Output is correct
10 Correct 19 ms 768 KB Output is correct
11 Correct 19 ms 888 KB Output is correct
12 Correct 19 ms 768 KB Output is correct
13 Correct 22 ms 768 KB Output is correct
14 Correct 19 ms 768 KB Output is correct
15 Correct 19 ms 768 KB Output is correct
16 Correct 23 ms 768 KB Output is correct
17 Correct 20 ms 896 KB Output is correct
18 Correct 21 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 19 ms 768 KB Output is correct
4 Correct 15 ms 928 KB Output is correct
5 Correct 19 ms 896 KB Output is correct
6 Correct 19 ms 768 KB Output is correct
7 Correct 19 ms 640 KB Output is correct
8 Correct 19 ms 760 KB Output is correct
9 Correct 19 ms 768 KB Output is correct
10 Correct 19 ms 768 KB Output is correct
11 Correct 19 ms 888 KB Output is correct
12 Correct 19 ms 768 KB Output is correct
13 Correct 22 ms 768 KB Output is correct
14 Correct 19 ms 768 KB Output is correct
15 Correct 19 ms 768 KB Output is correct
16 Correct 23 ms 768 KB Output is correct
17 Correct 20 ms 896 KB Output is correct
18 Correct 21 ms 768 KB Output is correct
19 Correct 215 ms 2040 KB Output is correct
20 Correct 272 ms 2296 KB Output is correct
21 Correct 263 ms 2304 KB Output is correct
22 Correct 281 ms 2296 KB Output is correct
23 Correct 263 ms 2272 KB Output is correct
24 Correct 261 ms 2296 KB Output is correct
25 Correct 266 ms 2304 KB Output is correct
26 Correct 282 ms 2296 KB Output is correct
27 Correct 274 ms 2296 KB Output is correct
28 Correct 267 ms 2304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 348 ms 3712 KB Output is correct
2 Correct 3413 ms 8060 KB Output is correct
3 Execution timed out 9102 ms 12280 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 19 ms 768 KB Output is correct
4 Correct 15 ms 928 KB Output is correct
5 Correct 19 ms 896 KB Output is correct
6 Correct 19 ms 768 KB Output is correct
7 Correct 19 ms 640 KB Output is correct
8 Correct 19 ms 760 KB Output is correct
9 Correct 19 ms 768 KB Output is correct
10 Correct 19 ms 768 KB Output is correct
11 Correct 19 ms 888 KB Output is correct
12 Correct 19 ms 768 KB Output is correct
13 Correct 22 ms 768 KB Output is correct
14 Correct 19 ms 768 KB Output is correct
15 Correct 19 ms 768 KB Output is correct
16 Correct 23 ms 768 KB Output is correct
17 Correct 20 ms 896 KB Output is correct
18 Correct 21 ms 768 KB Output is correct
19 Correct 215 ms 2040 KB Output is correct
20 Correct 272 ms 2296 KB Output is correct
21 Correct 263 ms 2304 KB Output is correct
22 Correct 281 ms 2296 KB Output is correct
23 Correct 263 ms 2272 KB Output is correct
24 Correct 261 ms 2296 KB Output is correct
25 Correct 266 ms 2304 KB Output is correct
26 Correct 282 ms 2296 KB Output is correct
27 Correct 274 ms 2296 KB Output is correct
28 Correct 267 ms 2304 KB Output is correct
29 Correct 348 ms 3712 KB Output is correct
30 Correct 3413 ms 8060 KB Output is correct
31 Execution timed out 9102 ms 12280 KB Time limit exceeded
32 Halted 0 ms 0 KB -