#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){
for(int i = 0; i < n; i++){
//cerr << i << " " << l << " " << r << "\n";
if(i < l || r < i){
if(ma.find(t[i]) != ma.end()) query(t[i]);
}
else{
if(ma.find(t[i]) == ma.end()) query(t[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:95:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
95 | if(r != t.size() + 1){
| ~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
492 KB |
Output is correct |
2 |
Correct |
23 ms |
492 KB |
Output is correct |
3 |
Correct |
73 ms |
876 KB |
Output is correct |
4 |
Correct |
320 ms |
1208 KB |
Output is correct |
5 |
Correct |
965 ms |
1928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
7 ms |
492 KB |
Output is correct |
6 |
Correct |
23 ms |
492 KB |
Output is correct |
7 |
Correct |
73 ms |
876 KB |
Output is correct |
8 |
Correct |
320 ms |
1208 KB |
Output is correct |
9 |
Correct |
965 ms |
1928 KB |
Output is correct |
10 |
Correct |
8 ms |
492 KB |
Output is correct |
11 |
Correct |
413 ms |
1440 KB |
Output is correct |
12 |
Correct |
956 ms |
2028 KB |
Output is correct |
13 |
Correct |
921 ms |
2028 KB |
Output is correct |
14 |
Correct |
916 ms |
2028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
7 ms |
492 KB |
Output is correct |
6 |
Correct |
23 ms |
492 KB |
Output is correct |
7 |
Correct |
73 ms |
876 KB |
Output is correct |
8 |
Correct |
320 ms |
1208 KB |
Output is correct |
9 |
Correct |
965 ms |
1928 KB |
Output is correct |
10 |
Correct |
8 ms |
492 KB |
Output is correct |
11 |
Correct |
413 ms |
1440 KB |
Output is correct |
12 |
Correct |
956 ms |
2028 KB |
Output is correct |
13 |
Correct |
921 ms |
2028 KB |
Output is correct |
14 |
Correct |
916 ms |
2028 KB |
Output is correct |
15 |
Execution timed out |
2762 ms |
4328 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
7 ms |
492 KB |
Output is correct |
6 |
Correct |
23 ms |
492 KB |
Output is correct |
7 |
Correct |
73 ms |
876 KB |
Output is correct |
8 |
Correct |
320 ms |
1208 KB |
Output is correct |
9 |
Correct |
965 ms |
1928 KB |
Output is correct |
10 |
Correct |
8 ms |
492 KB |
Output is correct |
11 |
Correct |
413 ms |
1440 KB |
Output is correct |
12 |
Correct |
956 ms |
2028 KB |
Output is correct |
13 |
Correct |
921 ms |
2028 KB |
Output is correct |
14 |
Correct |
916 ms |
2028 KB |
Output is correct |
15 |
Execution timed out |
2762 ms |
4328 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
7 ms |
492 KB |
Output is correct |
6 |
Correct |
23 ms |
492 KB |
Output is correct |
7 |
Correct |
73 ms |
876 KB |
Output is correct |
8 |
Correct |
320 ms |
1208 KB |
Output is correct |
9 |
Correct |
965 ms |
1928 KB |
Output is correct |
10 |
Correct |
8 ms |
492 KB |
Output is correct |
11 |
Correct |
413 ms |
1440 KB |
Output is correct |
12 |
Correct |
956 ms |
2028 KB |
Output is correct |
13 |
Correct |
921 ms |
2028 KB |
Output is correct |
14 |
Correct |
916 ms |
2028 KB |
Output is correct |
15 |
Execution timed out |
2762 ms |
4328 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
7 ms |
492 KB |
Output is correct |
6 |
Correct |
23 ms |
492 KB |
Output is correct |
7 |
Correct |
73 ms |
876 KB |
Output is correct |
8 |
Correct |
320 ms |
1208 KB |
Output is correct |
9 |
Correct |
965 ms |
1928 KB |
Output is correct |
10 |
Correct |
8 ms |
492 KB |
Output is correct |
11 |
Correct |
413 ms |
1440 KB |
Output is correct |
12 |
Correct |
956 ms |
2028 KB |
Output is correct |
13 |
Correct |
921 ms |
2028 KB |
Output is correct |
14 |
Correct |
916 ms |
2028 KB |
Output is correct |
15 |
Execution timed out |
2762 ms |
4328 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
7 ms |
492 KB |
Output is correct |
6 |
Correct |
23 ms |
492 KB |
Output is correct |
7 |
Correct |
73 ms |
876 KB |
Output is correct |
8 |
Correct |
320 ms |
1208 KB |
Output is correct |
9 |
Correct |
965 ms |
1928 KB |
Output is correct |
10 |
Correct |
8 ms |
492 KB |
Output is correct |
11 |
Correct |
413 ms |
1440 KB |
Output is correct |
12 |
Correct |
956 ms |
2028 KB |
Output is correct |
13 |
Correct |
921 ms |
2028 KB |
Output is correct |
14 |
Correct |
916 ms |
2028 KB |
Output is correct |
15 |
Execution timed out |
2762 ms |
4328 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
7 ms |
492 KB |
Output is correct |
6 |
Correct |
23 ms |
492 KB |
Output is correct |
7 |
Correct |
73 ms |
876 KB |
Output is correct |
8 |
Correct |
320 ms |
1208 KB |
Output is correct |
9 |
Correct |
965 ms |
1928 KB |
Output is correct |
10 |
Correct |
8 ms |
492 KB |
Output is correct |
11 |
Correct |
413 ms |
1440 KB |
Output is correct |
12 |
Correct |
956 ms |
2028 KB |
Output is correct |
13 |
Correct |
921 ms |
2028 KB |
Output is correct |
14 |
Correct |
916 ms |
2028 KB |
Output is correct |
15 |
Execution timed out |
2762 ms |
4328 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |