#include "minerals.h"
#include<bits/stdc++.h>
#define mp make_pair
#define F first
#define S second
#define iter(a) a.begin(), a.end()
#define lsort(a) sort(iter(a))
#define printv(a, b) { \
for(auto pv : a) b << pv << " "; \
b << "\n"; \
}
#define eb emplace_back
using namespace std;
typedef long long ll;
using pll = pair<ll, ll>;
using pii = pair<int, int>;
ostream& operator<<(ostream& o, pll p){
return o << '(' << p.F << ',' << p.S << ')';
}
vector<int> t;
vector<int> ans;
vector<pii> rng;
set<int> ma;
int query(int i){
if(ma.find(i) == ma.end()) ma.insert(i);
else ma.erase(i);
return Query(i);
}
int n;
void dothing(int l, int r){
set<int> oao;
for(int i = l; i <= r; i++){
oao.insert(t[i]);
}
set<int> del;
for(int i : ma){
if(oao.find(i) == oao.end()) del.insert(i);
}
for(int i : del) query(i);
for(int i : oao) if(ma.find(i) == ma.end()) query(i);
//cerr << l << " " << r << " ";
//printv(ma, cerr);
}
void check(int cnt, vector<int>& now, vector<int>& yes, vector<int>& no, int l, int r){
for(int i : now){
if(rng[i].S < l || r < rng[i].F){
no.eb(i);
continue;
}
int rs = query(i);
//cerr << "check " << l << " " << r << " " << i << " " << rng[i] << " " << rs << "\n";
if(rs == cnt) yes.eb(i);
else no.eb(i);
query(i);
}
}
void bs(int l, int r, vector<int>& now){
if(l > r || now.empty()) return;
//cerr << "bs " << l << " " << r << " ";
//printv(now, cerr);
if(l == r){
for(int i : now) ans[i] = t[l];
return;
}
int m = (l + r) / 2;
dothing(l, m);
//cerr << "ma ";
//printv(ma, cerr);
vector<int> yes, no;
check(m - l + 1, now, yes, no, l, m);
vector<int>().swap(now);
bs(l, m, yes);
bs(m + 1, r, no);
}
void Solve(int _n){
n = _n;
vector<int> now;
ans.resize(2 * n + 1, -1);
rng.resize(2 * n + 1);
for(int i = 1; i <= 2 * n; i++){
int r = query(i);
if(r != t.size() + 1){
now.eb(i);
query(i);
rng[i] = mp(0, (int)t.size() - 1);
}
else t.eb(i);
}
//printv(now, cerr);
//printv(t, cerr);
//printv(rng, cerr);
for(int i : t) query(i);
vector<int> tnow = now;
bs(0, n - 1, tnow);
//printv(ans, cerr);
for(int i : now){
Answer(i, ans[i]);
}
}
Compilation message
minerals.cpp: In function 'void Solve(int)':
minerals.cpp:96:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
96 | if(r != t.size() + 1){
| ~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
492 KB |
Output is correct |
2 |
Correct |
7 ms |
492 KB |
Output is correct |
3 |
Correct |
17 ms |
748 KB |
Output is correct |
4 |
Correct |
37 ms |
1260 KB |
Output is correct |
5 |
Correct |
78 ms |
2028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
3 ms |
492 KB |
Output is correct |
6 |
Correct |
7 ms |
492 KB |
Output is correct |
7 |
Correct |
17 ms |
748 KB |
Output is correct |
8 |
Correct |
37 ms |
1260 KB |
Output is correct |
9 |
Correct |
78 ms |
2028 KB |
Output is correct |
10 |
Correct |
4 ms |
492 KB |
Output is correct |
11 |
Correct |
48 ms |
1516 KB |
Output is correct |
12 |
Correct |
77 ms |
2028 KB |
Output is correct |
13 |
Correct |
83 ms |
1900 KB |
Output is correct |
14 |
Correct |
75 ms |
2028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
3 ms |
492 KB |
Output is correct |
6 |
Correct |
7 ms |
492 KB |
Output is correct |
7 |
Correct |
17 ms |
748 KB |
Output is correct |
8 |
Correct |
37 ms |
1260 KB |
Output is correct |
9 |
Correct |
78 ms |
2028 KB |
Output is correct |
10 |
Correct |
4 ms |
492 KB |
Output is correct |
11 |
Correct |
48 ms |
1516 KB |
Output is correct |
12 |
Correct |
77 ms |
2028 KB |
Output is correct |
13 |
Correct |
83 ms |
1900 KB |
Output is correct |
14 |
Correct |
75 ms |
2028 KB |
Output is correct |
15 |
Incorrect |
160 ms |
4456 KB |
Wrong Answer [2] |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
3 ms |
492 KB |
Output is correct |
6 |
Correct |
7 ms |
492 KB |
Output is correct |
7 |
Correct |
17 ms |
748 KB |
Output is correct |
8 |
Correct |
37 ms |
1260 KB |
Output is correct |
9 |
Correct |
78 ms |
2028 KB |
Output is correct |
10 |
Correct |
4 ms |
492 KB |
Output is correct |
11 |
Correct |
48 ms |
1516 KB |
Output is correct |
12 |
Correct |
77 ms |
2028 KB |
Output is correct |
13 |
Correct |
83 ms |
1900 KB |
Output is correct |
14 |
Correct |
75 ms |
2028 KB |
Output is correct |
15 |
Incorrect |
160 ms |
4456 KB |
Wrong Answer [2] |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
3 ms |
492 KB |
Output is correct |
6 |
Correct |
7 ms |
492 KB |
Output is correct |
7 |
Correct |
17 ms |
748 KB |
Output is correct |
8 |
Correct |
37 ms |
1260 KB |
Output is correct |
9 |
Correct |
78 ms |
2028 KB |
Output is correct |
10 |
Correct |
4 ms |
492 KB |
Output is correct |
11 |
Correct |
48 ms |
1516 KB |
Output is correct |
12 |
Correct |
77 ms |
2028 KB |
Output is correct |
13 |
Correct |
83 ms |
1900 KB |
Output is correct |
14 |
Correct |
75 ms |
2028 KB |
Output is correct |
15 |
Incorrect |
160 ms |
4456 KB |
Wrong Answer [2] |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
3 ms |
492 KB |
Output is correct |
6 |
Correct |
7 ms |
492 KB |
Output is correct |
7 |
Correct |
17 ms |
748 KB |
Output is correct |
8 |
Correct |
37 ms |
1260 KB |
Output is correct |
9 |
Correct |
78 ms |
2028 KB |
Output is correct |
10 |
Correct |
4 ms |
492 KB |
Output is correct |
11 |
Correct |
48 ms |
1516 KB |
Output is correct |
12 |
Correct |
77 ms |
2028 KB |
Output is correct |
13 |
Correct |
83 ms |
1900 KB |
Output is correct |
14 |
Correct |
75 ms |
2028 KB |
Output is correct |
15 |
Incorrect |
160 ms |
4456 KB |
Wrong Answer [2] |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
3 ms |
492 KB |
Output is correct |
6 |
Correct |
7 ms |
492 KB |
Output is correct |
7 |
Correct |
17 ms |
748 KB |
Output is correct |
8 |
Correct |
37 ms |
1260 KB |
Output is correct |
9 |
Correct |
78 ms |
2028 KB |
Output is correct |
10 |
Correct |
4 ms |
492 KB |
Output is correct |
11 |
Correct |
48 ms |
1516 KB |
Output is correct |
12 |
Correct |
77 ms |
2028 KB |
Output is correct |
13 |
Correct |
83 ms |
1900 KB |
Output is correct |
14 |
Correct |
75 ms |
2028 KB |
Output is correct |
15 |
Incorrect |
160 ms |
4456 KB |
Wrong Answer [2] |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
3 ms |
492 KB |
Output is correct |
6 |
Correct |
7 ms |
492 KB |
Output is correct |
7 |
Correct |
17 ms |
748 KB |
Output is correct |
8 |
Correct |
37 ms |
1260 KB |
Output is correct |
9 |
Correct |
78 ms |
2028 KB |
Output is correct |
10 |
Correct |
4 ms |
492 KB |
Output is correct |
11 |
Correct |
48 ms |
1516 KB |
Output is correct |
12 |
Correct |
77 ms |
2028 KB |
Output is correct |
13 |
Correct |
83 ms |
1900 KB |
Output is correct |
14 |
Correct |
75 ms |
2028 KB |
Output is correct |
15 |
Incorrect |
160 ms |
4456 KB |
Wrong Answer [2] |
16 |
Halted |
0 ms |
0 KB |
- |