Submission #133766

# Submission time Handle Problem Language Result Execution time Memory
133766 2019-07-21T10:06:02 Z hamzqq9 Minerals (JOI19_minerals) C++14
90 / 100
107 ms 3444 KB
#include "minerals.h"
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define ppb pop_back
#define ii pair<int,int>
#define ll long long
#define orta ((bas+son)>>1)
#define sz(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define umin(x,y) x=min(x,y)
#define umax(x,y) x=max(x,y)
#define inf 2000000000000000
#define N 500005
#define MOD 998244353
#define KOK 700		
using namespace std;

vector<int> A,B;
vector<int> p;
vector<int> on;
int cnt;

mt19937 rnd;

void make(int l,int mid,int r) {

	for(int i=l;i<=mid;i++) {

		if(!on[i]) cnt=Query(p[A[i]]),on[i]=!on[i];

	}

	for(int i=mid+1;i<=r;i++) {

		if(on[i]) cnt=Query(p[A[i]]),on[i]=!on[i];

	}

}

void solve(int l,int r,vector<int> cd) {

	if(l==r) {

		for(auto x:cd) Answer(p[x],p[A[l]]);

		return ;

	}

	int mid=(l+r)>>1;

	make(l,mid,r);

	vector<int> lcd,rcd;

	bool tol=0,tor=0;

	shuffle(cd.begin(),cd.end(),rnd);

	for(auto x:cd) {

		if(tol) {lcd.pb(x);continue ;}
		if(tor) {rcd.pb(x);continue ;}

		int cur=Query(p[x]);

		if(cnt!=cur) {

			rcd.pb(x);

		}
		else {

			lcd.pb(x);

		}

		cnt=cur;

		if(sz(lcd)==mid-l+1) tor=1;
		if(sz(rcd)==r-mid) tol=1;

	}

	solve(l,mid,lcd);
	solve(mid+1,r,rcd);

}

void Solve(int n) {
 
	n<<=1;
 
	rnd=mt19937(time(NULL));
 
 	on=vector<int>(n,0);

	for(int i=1;i<=n;i++) p.pb(i);
 
	shuffle(p.begin(),p.end(),rnd);

	bool toA=0,toB=0;
	
	for(int i=0;i<n;i++) {
 
		if(toA) {A.pb(i);continue ;}
		if(toB) {B.pb(i);continue ;}		

		int cur=Query(p[i]);

		on[i]=!on[i];
 
		if(cur>cnt) {
 
			A.pb(i);
			
		}
		else {

			B.pb(i);
 
		}

		if(sz(A)==n/2) toB=1;
		if(sz(B)==n/2) toA=1;
 
		cnt=cur;
 
	}
	
	solve(0,sz(A)-1,B);
 
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 248 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 4 ms 376 KB Output is correct
3 Correct 8 ms 632 KB Output is correct
4 Correct 15 ms 888 KB Output is correct
5 Correct 29 ms 1272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 248 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 248 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 4 ms 376 KB Output is correct
7 Correct 8 ms 632 KB Output is correct
8 Correct 15 ms 888 KB Output is correct
9 Correct 29 ms 1272 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 19 ms 1016 KB Output is correct
12 Correct 29 ms 1400 KB Output is correct
13 Correct 28 ms 1420 KB Output is correct
14 Correct 29 ms 1320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 248 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 248 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 4 ms 376 KB Output is correct
7 Correct 8 ms 632 KB Output is correct
8 Correct 15 ms 888 KB Output is correct
9 Correct 29 ms 1272 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 19 ms 1016 KB Output is correct
12 Correct 29 ms 1400 KB Output is correct
13 Correct 28 ms 1420 KB Output is correct
14 Correct 29 ms 1320 KB Output is correct
15 Correct 87 ms 3132 KB Output is correct
16 Correct 86 ms 3104 KB Output is correct
17 Correct 82 ms 3184 KB Output is correct
18 Correct 83 ms 2928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 248 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 248 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 4 ms 376 KB Output is correct
7 Correct 8 ms 632 KB Output is correct
8 Correct 15 ms 888 KB Output is correct
9 Correct 29 ms 1272 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 19 ms 1016 KB Output is correct
12 Correct 29 ms 1400 KB Output is correct
13 Correct 28 ms 1420 KB Output is correct
14 Correct 29 ms 1320 KB Output is correct
15 Correct 87 ms 3132 KB Output is correct
16 Correct 86 ms 3104 KB Output is correct
17 Correct 82 ms 3184 KB Output is correct
18 Correct 83 ms 2928 KB Output is correct
19 Correct 89 ms 3184 KB Output is correct
20 Correct 92 ms 3180 KB Output is correct
21 Correct 84 ms 3184 KB Output is correct
22 Correct 87 ms 3056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 248 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 248 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 4 ms 376 KB Output is correct
7 Correct 8 ms 632 KB Output is correct
8 Correct 15 ms 888 KB Output is correct
9 Correct 29 ms 1272 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 19 ms 1016 KB Output is correct
12 Correct 29 ms 1400 KB Output is correct
13 Correct 28 ms 1420 KB Output is correct
14 Correct 29 ms 1320 KB Output is correct
15 Correct 87 ms 3132 KB Output is correct
16 Correct 86 ms 3104 KB Output is correct
17 Correct 82 ms 3184 KB Output is correct
18 Correct 83 ms 2928 KB Output is correct
19 Correct 89 ms 3184 KB Output is correct
20 Correct 92 ms 3180 KB Output is correct
21 Correct 84 ms 3184 KB Output is correct
22 Correct 87 ms 3056 KB Output is correct
23 Correct 89 ms 3232 KB Output is correct
24 Correct 90 ms 3184 KB Output is correct
25 Correct 89 ms 3256 KB Output is correct
26 Correct 87 ms 3152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 248 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 248 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 4 ms 376 KB Output is correct
7 Correct 8 ms 632 KB Output is correct
8 Correct 15 ms 888 KB Output is correct
9 Correct 29 ms 1272 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 19 ms 1016 KB Output is correct
12 Correct 29 ms 1400 KB Output is correct
13 Correct 28 ms 1420 KB Output is correct
14 Correct 29 ms 1320 KB Output is correct
15 Correct 87 ms 3132 KB Output is correct
16 Correct 86 ms 3104 KB Output is correct
17 Correct 82 ms 3184 KB Output is correct
18 Correct 83 ms 2928 KB Output is correct
19 Correct 89 ms 3184 KB Output is correct
20 Correct 92 ms 3180 KB Output is correct
21 Correct 84 ms 3184 KB Output is correct
22 Correct 87 ms 3056 KB Output is correct
23 Correct 89 ms 3232 KB Output is correct
24 Correct 90 ms 3184 KB Output is correct
25 Correct 89 ms 3256 KB Output is correct
26 Correct 87 ms 3152 KB Output is correct
27 Correct 93 ms 3312 KB Output is correct
28 Correct 93 ms 3312 KB Output is correct
29 Correct 93 ms 3404 KB Output is correct
30 Correct 92 ms 3160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 248 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 248 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 4 ms 376 KB Output is correct
7 Correct 8 ms 632 KB Output is correct
8 Correct 15 ms 888 KB Output is correct
9 Correct 29 ms 1272 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 19 ms 1016 KB Output is correct
12 Correct 29 ms 1400 KB Output is correct
13 Correct 28 ms 1420 KB Output is correct
14 Correct 29 ms 1320 KB Output is correct
15 Correct 87 ms 3132 KB Output is correct
16 Correct 86 ms 3104 KB Output is correct
17 Correct 82 ms 3184 KB Output is correct
18 Correct 83 ms 2928 KB Output is correct
19 Correct 89 ms 3184 KB Output is correct
20 Correct 92 ms 3180 KB Output is correct
21 Correct 84 ms 3184 KB Output is correct
22 Correct 87 ms 3056 KB Output is correct
23 Correct 89 ms 3232 KB Output is correct
24 Correct 90 ms 3184 KB Output is correct
25 Correct 89 ms 3256 KB Output is correct
26 Correct 87 ms 3152 KB Output is correct
27 Correct 93 ms 3312 KB Output is correct
28 Correct 93 ms 3312 KB Output is correct
29 Correct 93 ms 3404 KB Output is correct
30 Correct 92 ms 3160 KB Output is correct
31 Correct 97 ms 3396 KB Output is correct
32 Correct 100 ms 3400 KB Output is correct
33 Correct 107 ms 3440 KB Output is correct
34 Correct 93 ms 3244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 248 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 248 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 4 ms 376 KB Output is correct
7 Correct 8 ms 632 KB Output is correct
8 Correct 15 ms 888 KB Output is correct
9 Correct 29 ms 1272 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 19 ms 1016 KB Output is correct
12 Correct 29 ms 1400 KB Output is correct
13 Correct 28 ms 1420 KB Output is correct
14 Correct 29 ms 1320 KB Output is correct
15 Correct 87 ms 3132 KB Output is correct
16 Correct 86 ms 3104 KB Output is correct
17 Correct 82 ms 3184 KB Output is correct
18 Correct 83 ms 2928 KB Output is correct
19 Correct 89 ms 3184 KB Output is correct
20 Correct 92 ms 3180 KB Output is correct
21 Correct 84 ms 3184 KB Output is correct
22 Correct 87 ms 3056 KB Output is correct
23 Correct 89 ms 3232 KB Output is correct
24 Correct 90 ms 3184 KB Output is correct
25 Correct 89 ms 3256 KB Output is correct
26 Correct 87 ms 3152 KB Output is correct
27 Correct 93 ms 3312 KB Output is correct
28 Correct 93 ms 3312 KB Output is correct
29 Correct 93 ms 3404 KB Output is correct
30 Correct 92 ms 3160 KB Output is correct
31 Correct 97 ms 3396 KB Output is correct
32 Correct 100 ms 3400 KB Output is correct
33 Correct 107 ms 3440 KB Output is correct
34 Correct 93 ms 3244 KB Output is correct
35 Incorrect 94 ms 3444 KB Wrong Answer [2]
36 Halted 0 ms 0 KB -