This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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);
}
}
// for(auto i:temp){
// Query(i);
// }
queue<tuple<vector<int>,int,int,bool,bool>>Q;
Q.push({temp,0,n-1,1,1});
while(sz(Q)){
auto [cur,l,r,flag,flag2]=Q.front();
Q.pop();
if(l==r){
Answer(cur[0],cur2[l]);
continue;
}
int mm=l+r>>1;
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;
if(!flag){
for(auto i:cur){
int x=Query(i);
if(x==dick){
L.pb(i);
}
else{
R.pb(i);
}
dick=x;
//Query(i);
}
}
else{
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-flag,1});
}
if(sz(R)){
Q.push({R,mm+1,r,1-flag,0});
}
}
for(int i=1;i<=2*n;i++){
Query(i);
}
//dac(temp,0,n-1);
}
/*
4nlog2n+4n
*/
/////////////////
#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 (stderr)
minerals.cpp: In function 'void Solve(int)':
minerals.cpp:76:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
76 | auto [cur,l,r,flag,flag2]=Q.front();
| ^
minerals.cpp:82:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
82 | int mm=l+r>>1;
| ~^~
minerals.cpp:98:17: warning: 'dick' may be used uninitialized in this function [-Wmaybe-uninitialized]
98 | if(x==dick){
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |