Submission #201116

# Submission time Handle Problem Language Result Execution time Memory
201116 2020-02-09T11:27:54 Z grt Tenis (COI19_tenis) C++17
100 / 100
180 ms 7928 KB
#include <bits/stdc++.h>
#define PB push_back
#define ST first
#define ND second
#define _ ios_base::sync_with_stdio(0); cin.tie(0);
//mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

using namespace std;

using ll = long long;
using pi = pair<int,int>;
using vi = vector<int>;

struct Node {
	int f,g;
};

const int nax = 100*1000+10;
int n,q;
int t[3][nax],ord[3][nax];
Node T[(1<<18)];

int last(int a) {
	return max({ord[0][a],ord[1][a],ord[2][a]});
}

void propagate(int a) {
	T[2*a].g+=T[a].g;
	T[2*a+1].g+=T[a].g;
	T[a].g=0;
}

void init(int l,int r,int v) {
	if(l==r) {
		T[v].f = l;
		return;
	}
	int mid = (l+r)/2;
	init(l,mid,v*2);
	init(mid+1,r,v*2+1);
	T[v].f = min(T[v*2].f,T[v*2+1].f);
}

void update(int a,int b,int l,int r,int v,int val) {
	if(a<=l&&r<=b) {
		T[v].g+=val;
		return;
	}
	propagate(v);
	int mid = (l+r)/2;
	if(a<=mid) update(a,b,l,mid,v*2,val);
	if(mid<b) update(a,b,mid+1,r,v*2+1,val);
	T[v].f = min(T[2*v].f-T[2*v].g,T[2*v+1].f-T[2*v+1].g);
}

int query(int l, int r, int v) {
	if(l==r) {
		return l;
	}
	propagate(v);
	int mid = (l+r)/2,w=-1;
	if(T[2*v].f-T[2*v].g==0) {
		w = query(l,mid,v*2);
	} else {
		w = query(mid+1,r,v*2+1);
	}
	T[v].f = min(T[2*v].f-T[2*v].g,T[2*v+1].f-T[2*v+1].g);
	return w;
}

void coutTree(int l,int r,int v) {
	if(l==r) {
		cout<<l<<" "<<l<<" : "<<T[l].f<<" "<<T[l].g<<"\n";
		return;
	}
	int mid = (l+r)/2;
	coutTree(l,mid,v*2);
	coutTree(mid+1,r,v*2+1);
	cout<<l<<" "<<r<<" : "<<T[l].f<<" "<<T[r].g<<"\n";
}

int main() {_
	cin>>n>>q;
	for(int j=0; j<3; j++) {
		for(int i=1; i<=n; i++) {
			cin>>t[j][i];
			ord[j][t[j][i]] = i;
		}
	}
	init(1,n,1);
	for(int i=1; i<=n; i++) {
		update(last(i),n,1,n,1,1);
	}
	while(q--) {
		int typ,a,b,c;
		cin>>typ;
		if(typ==1) {
			cin>>a;
			int tmp = query(1,n,1);
			//cout<<tmp<<" ";
			cout<<(last(a)>tmp?"NE\n":"DA\n");
		} else {
			cin>>c>>a>>b;
			update(last(a),n,1,n,1,-1);
			update(last(b),n,1,n,1,-1);
			swap(ord[c-1][a],ord[c-1][b]);
			update(last(a),n,1,n,1,1);
			update(last(b),n,1,n,1,1);
			//cout<<last(a)<<" "<<last(b)<<"\n";
		}
		//coutTree(1,n,1);
	}
	
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 6 ms 376 KB Output is correct
8 Correct 6 ms 504 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 504 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 6 ms 376 KB Output is correct
8 Correct 6 ms 504 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 504 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 504 KB Output is correct
13 Correct 69 ms 6392 KB Output is correct
14 Correct 75 ms 6504 KB Output is correct
15 Correct 67 ms 6392 KB Output is correct
16 Correct 68 ms 6520 KB Output is correct
17 Correct 69 ms 6392 KB Output is correct
18 Correct 70 ms 6392 KB Output is correct
19 Correct 68 ms 6492 KB Output is correct
20 Correct 78 ms 6392 KB Output is correct
21 Correct 64 ms 6392 KB Output is correct
22 Correct 72 ms 6520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 105 ms 7544 KB Output is correct
2 Correct 101 ms 7544 KB Output is correct
3 Correct 110 ms 7700 KB Output is correct
4 Correct 104 ms 7672 KB Output is correct
5 Correct 104 ms 7544 KB Output is correct
6 Correct 102 ms 7544 KB Output is correct
7 Correct 98 ms 7544 KB Output is correct
8 Correct 106 ms 7544 KB Output is correct
9 Correct 112 ms 7484 KB Output is correct
10 Correct 102 ms 7544 KB Output is correct
11 Correct 103 ms 7544 KB Output is correct
12 Correct 98 ms 7544 KB Output is correct
13 Correct 122 ms 7672 KB Output is correct
14 Correct 105 ms 7544 KB Output is correct
15 Correct 98 ms 7544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 6 ms 376 KB Output is correct
8 Correct 6 ms 504 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 504 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 504 KB Output is correct
13 Correct 69 ms 6392 KB Output is correct
14 Correct 75 ms 6504 KB Output is correct
15 Correct 67 ms 6392 KB Output is correct
16 Correct 68 ms 6520 KB Output is correct
17 Correct 69 ms 6392 KB Output is correct
18 Correct 70 ms 6392 KB Output is correct
19 Correct 68 ms 6492 KB Output is correct
20 Correct 78 ms 6392 KB Output is correct
21 Correct 64 ms 6392 KB Output is correct
22 Correct 72 ms 6520 KB Output is correct
23 Correct 105 ms 7544 KB Output is correct
24 Correct 101 ms 7544 KB Output is correct
25 Correct 110 ms 7700 KB Output is correct
26 Correct 104 ms 7672 KB Output is correct
27 Correct 104 ms 7544 KB Output is correct
28 Correct 102 ms 7544 KB Output is correct
29 Correct 98 ms 7544 KB Output is correct
30 Correct 106 ms 7544 KB Output is correct
31 Correct 112 ms 7484 KB Output is correct
32 Correct 102 ms 7544 KB Output is correct
33 Correct 103 ms 7544 KB Output is correct
34 Correct 98 ms 7544 KB Output is correct
35 Correct 122 ms 7672 KB Output is correct
36 Correct 105 ms 7544 KB Output is correct
37 Correct 98 ms 7544 KB Output is correct
38 Correct 174 ms 7800 KB Output is correct
39 Correct 123 ms 7544 KB Output is correct
40 Correct 180 ms 7800 KB Output is correct
41 Correct 128 ms 7672 KB Output is correct
42 Correct 139 ms 7800 KB Output is correct
43 Correct 175 ms 7800 KB Output is correct
44 Correct 127 ms 7672 KB Output is correct
45 Correct 136 ms 7672 KB Output is correct
46 Correct 118 ms 7672 KB Output is correct
47 Correct 127 ms 7804 KB Output is correct
48 Correct 117 ms 7548 KB Output is correct
49 Correct 128 ms 7672 KB Output is correct
50 Correct 117 ms 7672 KB Output is correct
51 Correct 141 ms 7800 KB Output is correct
52 Correct 169 ms 7928 KB Output is correct
53 Correct 128 ms 7672 KB Output is correct
54 Correct 135 ms 7836 KB Output is correct
55 Correct 136 ms 7672 KB Output is correct
56 Correct 129 ms 7668 KB Output is correct
57 Correct 130 ms 7672 KB Output is correct
58 Correct 133 ms 7672 KB Output is correct