#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define pb push_back
#define sz(x) (int)(x.size())
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define vi vector<int>
#define vp vector<pii>
#define vvi vector<vi>
const int mxn=43000;
#ifdef local
void setio(){freopen("/Users/iantsai/Library/Mobile Documents/com~apple~CloudDocs/cpp/Empty.md","r",stdin);}
set<int>cur;
int color[mxn];
int cnt[mxn];
int n;
bool ok;
int tt=0;
void init(){
cin>>n;
for(int i=1;i<=2*n;i++){
cin>>color[i];
}
}
int res;
int Query(int x){
tt++;
if(cur.find(x)!=cur.end()){
cur.erase(x);
cnt[color[x]]--;
if(cnt[color[x]]==0)res--;
}
else{
cur.insert(x);
cnt[color[x]]++;
if(cnt[color[x]]==1)res++;
}
return res;
}
void Answer(int a,int b){
if(a>b)swap(a,b);
cout<<a<<' '<<b<<'\n';
if(color[a]!=color[b]){
ok=0;
}
}
#else
void setio(){}
#include "minerals.h"
#endif
//////////////////
vector<int>cur2;
void Solve(int n){
vector<int>temp;
int prev=0;
for(int i=1;i<=2*n;i++){
if(Query(i)==prev+1){
prev++;
temp.pb(i);
}
else{
cur2.pb(i);
}
}
queue<tuple<vector<int>,int,int,bool>>Q;
Q.push({temp,0,n-1,1});
while(sz(Q)){
auto [cur,l,r,flag2]=Q.front();
Q.pop();
if(l==r){
Answer(cur[0],cur2[l]);
continue;
}
int mm;
int len=(r-l)*0.33;
if(flag2){
mm=max(l,min(r-1,r-len));
}
else{
mm=min(r-1,max(l,l+len));
}
int dick;
if(flag2){
for(int i=mm+1;i<=r;i++){
dick=Query(cur2[i]);
}
}
else{
for(int i=l;i<=mm;i++){
dick=Query(cur2[i]);
}
}
vector<int>L,R;
for(auto i:cur){
int x=Query(i);
if(x==dick){
L.pb(i);
}
else{
R.pb(i);
}
dick=x;
}
if(sz(L)){
Q.push({L,l,mm,1});
}
if(sz(R)){
Q.push({R,mm+1,r,0});
}
}
}
#ifdef local
int main(){
ok=1;
tt=0;
setio();
init();
Solve(n);
cout<<tt<<'\n';
if(ok)cout<<"Accepted!\n";
else cout<<"Wrong Answer\n";
}
#else
#endif
/*
input:
///////////////
///////
//
/
/
/
*/
Compilation message
minerals.cpp: In function 'void Solve(int)':
minerals.cpp:73:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
73 | auto [cur,l,r,flag2]=Q.front();
| ^
minerals.cpp:101:13: warning: 'dick' may be used uninitialized in this function [-Wmaybe-uninitialized]
101 | if(x==dick){
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
600 KB |
Output is correct |
4 |
Correct |
5 ms |
856 KB |
Output is correct |
5 |
Correct |
9 ms |
1360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
600 KB |
Output is correct |
8 |
Correct |
5 ms |
856 KB |
Output is correct |
9 |
Correct |
9 ms |
1360 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
6 ms |
1024 KB |
Output is correct |
12 |
Correct |
10 ms |
1612 KB |
Output is correct |
13 |
Correct |
7 ms |
1640 KB |
Output is correct |
14 |
Correct |
7 ms |
1536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
600 KB |
Output is correct |
8 |
Correct |
5 ms |
856 KB |
Output is correct |
9 |
Correct |
9 ms |
1360 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
6 ms |
1024 KB |
Output is correct |
12 |
Correct |
10 ms |
1612 KB |
Output is correct |
13 |
Correct |
7 ms |
1640 KB |
Output is correct |
14 |
Correct |
7 ms |
1536 KB |
Output is correct |
15 |
Correct |
26 ms |
2872 KB |
Output is correct |
16 |
Correct |
26 ms |
2996 KB |
Output is correct |
17 |
Correct |
20 ms |
3084 KB |
Output is correct |
18 |
Correct |
19 ms |
3372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
600 KB |
Output is correct |
8 |
Correct |
5 ms |
856 KB |
Output is correct |
9 |
Correct |
9 ms |
1360 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
6 ms |
1024 KB |
Output is correct |
12 |
Correct |
10 ms |
1612 KB |
Output is correct |
13 |
Correct |
7 ms |
1640 KB |
Output is correct |
14 |
Correct |
7 ms |
1536 KB |
Output is correct |
15 |
Correct |
26 ms |
2872 KB |
Output is correct |
16 |
Correct |
26 ms |
2996 KB |
Output is correct |
17 |
Correct |
20 ms |
3084 KB |
Output is correct |
18 |
Correct |
19 ms |
3372 KB |
Output is correct |
19 |
Correct |
26 ms |
2864 KB |
Output is correct |
20 |
Correct |
26 ms |
3016 KB |
Output is correct |
21 |
Correct |
19 ms |
3184 KB |
Output is correct |
22 |
Correct |
19 ms |
3568 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
600 KB |
Output is correct |
8 |
Correct |
5 ms |
856 KB |
Output is correct |
9 |
Correct |
9 ms |
1360 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
6 ms |
1024 KB |
Output is correct |
12 |
Correct |
10 ms |
1612 KB |
Output is correct |
13 |
Correct |
7 ms |
1640 KB |
Output is correct |
14 |
Correct |
7 ms |
1536 KB |
Output is correct |
15 |
Correct |
26 ms |
2872 KB |
Output is correct |
16 |
Correct |
26 ms |
2996 KB |
Output is correct |
17 |
Correct |
20 ms |
3084 KB |
Output is correct |
18 |
Correct |
19 ms |
3372 KB |
Output is correct |
19 |
Correct |
26 ms |
2864 KB |
Output is correct |
20 |
Correct |
26 ms |
3016 KB |
Output is correct |
21 |
Correct |
19 ms |
3184 KB |
Output is correct |
22 |
Correct |
19 ms |
3568 KB |
Output is correct |
23 |
Correct |
27 ms |
3132 KB |
Output is correct |
24 |
Correct |
26 ms |
3132 KB |
Output is correct |
25 |
Correct |
20 ms |
3124 KB |
Output is correct |
26 |
Correct |
20 ms |
2804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
600 KB |
Output is correct |
8 |
Correct |
5 ms |
856 KB |
Output is correct |
9 |
Correct |
9 ms |
1360 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
6 ms |
1024 KB |
Output is correct |
12 |
Correct |
10 ms |
1612 KB |
Output is correct |
13 |
Correct |
7 ms |
1640 KB |
Output is correct |
14 |
Correct |
7 ms |
1536 KB |
Output is correct |
15 |
Correct |
26 ms |
2872 KB |
Output is correct |
16 |
Correct |
26 ms |
2996 KB |
Output is correct |
17 |
Correct |
20 ms |
3084 KB |
Output is correct |
18 |
Correct |
19 ms |
3372 KB |
Output is correct |
19 |
Correct |
26 ms |
2864 KB |
Output is correct |
20 |
Correct |
26 ms |
3016 KB |
Output is correct |
21 |
Correct |
19 ms |
3184 KB |
Output is correct |
22 |
Correct |
19 ms |
3568 KB |
Output is correct |
23 |
Correct |
27 ms |
3132 KB |
Output is correct |
24 |
Correct |
26 ms |
3132 KB |
Output is correct |
25 |
Correct |
20 ms |
3124 KB |
Output is correct |
26 |
Correct |
20 ms |
2804 KB |
Output is correct |
27 |
Incorrect |
27 ms |
3116 KB |
Wrong Answer [2] |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
600 KB |
Output is correct |
8 |
Correct |
5 ms |
856 KB |
Output is correct |
9 |
Correct |
9 ms |
1360 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
6 ms |
1024 KB |
Output is correct |
12 |
Correct |
10 ms |
1612 KB |
Output is correct |
13 |
Correct |
7 ms |
1640 KB |
Output is correct |
14 |
Correct |
7 ms |
1536 KB |
Output is correct |
15 |
Correct |
26 ms |
2872 KB |
Output is correct |
16 |
Correct |
26 ms |
2996 KB |
Output is correct |
17 |
Correct |
20 ms |
3084 KB |
Output is correct |
18 |
Correct |
19 ms |
3372 KB |
Output is correct |
19 |
Correct |
26 ms |
2864 KB |
Output is correct |
20 |
Correct |
26 ms |
3016 KB |
Output is correct |
21 |
Correct |
19 ms |
3184 KB |
Output is correct |
22 |
Correct |
19 ms |
3568 KB |
Output is correct |
23 |
Correct |
27 ms |
3132 KB |
Output is correct |
24 |
Correct |
26 ms |
3132 KB |
Output is correct |
25 |
Correct |
20 ms |
3124 KB |
Output is correct |
26 |
Correct |
20 ms |
2804 KB |
Output is correct |
27 |
Incorrect |
27 ms |
3116 KB |
Wrong Answer [2] |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
600 KB |
Output is correct |
8 |
Correct |
5 ms |
856 KB |
Output is correct |
9 |
Correct |
9 ms |
1360 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
6 ms |
1024 KB |
Output is correct |
12 |
Correct |
10 ms |
1612 KB |
Output is correct |
13 |
Correct |
7 ms |
1640 KB |
Output is correct |
14 |
Correct |
7 ms |
1536 KB |
Output is correct |
15 |
Correct |
26 ms |
2872 KB |
Output is correct |
16 |
Correct |
26 ms |
2996 KB |
Output is correct |
17 |
Correct |
20 ms |
3084 KB |
Output is correct |
18 |
Correct |
19 ms |
3372 KB |
Output is correct |
19 |
Correct |
26 ms |
2864 KB |
Output is correct |
20 |
Correct |
26 ms |
3016 KB |
Output is correct |
21 |
Correct |
19 ms |
3184 KB |
Output is correct |
22 |
Correct |
19 ms |
3568 KB |
Output is correct |
23 |
Correct |
27 ms |
3132 KB |
Output is correct |
24 |
Correct |
26 ms |
3132 KB |
Output is correct |
25 |
Correct |
20 ms |
3124 KB |
Output is correct |
26 |
Correct |
20 ms |
2804 KB |
Output is correct |
27 |
Incorrect |
27 ms |
3116 KB |
Wrong Answer [2] |
28 |
Halted |
0 ms |
0 KB |
- |