#include <iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <algorithm>
//#define debug(x) cerr << #x << " " << x << "\n"
#pragma GCC optimize("Ofast,unroll-loops")
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
const int bSize = 100;
const int bits = 18;
const int NMAX = 100000;
const int VMAX = NMAX * 89;
int a[NMAX], n;
int u;
struct BLOCK {
int time;
vector <int> v;
};
class DS {
public:
vector <BLOCK> blocks;
vector <pii> changes;
unordered_set <int> vecini;
void baga(int x, int cand) {
if(vecini.find(x) != vecini.end()) {
vecini.erase(x);
changes.push_back({x, cand});
} else {
vecini.insert(x);
changes.push_back({x, cand});
}
if(changes.size() % bSize == 0) {
BLOCK nou;
nou.v.clear();
nou.time = cand;
for(auto x : vecini) {
nou.v.push_back(x);
}
blocks.push_back(nou);
}
}
} ds[NMAX];
void init(int N, int D, int H[]) {
n = N;
for(int i = 0; i < N; i++) {
a[i] = H[i];
}
}
void curseChanges(int U, int A[], int B[]) {
u = U;
for(int i = 0; i < U; i++) {
int timp = i + 1;
ds[A[i]].baga(B[i], timp);
ds[B[i]].baga(A[i], timp);
}
}
int question(int x, int y, int v) {
int r = -1;
int timpX = 0, timpY = 0;
int pas = (1 << bits);
while(pas) {
if(r + pas < ds[x].blocks.size() && ds[x].blocks[r + pas].time <= v)
r += pas;
pas /= 2;
}
unordered_set <int> stX;
if(r != -1) {
timpX = ds[x].blocks[r].time + 1;
for(auto p : ds[x].blocks[r].v)
stX.insert(p);
}
r = -1;
pas = (1 << bits);
while(pas) {
if(r + pas < ds[y].blocks.size() && ds[y].blocks[r + pas].time <= v)
r += pas;
pas /= 2;
}
unordered_set <int> stY;
if(r != -1) {
timpY = ds[y].blocks[r].time + 1;
for(auto p : ds[y].blocks[r].v)
stY.insert(p);
}
r = -1, pas = (1 << 18);
while(pas){
if(r + pas < ds[x].changes.size() && ds[x].changes[r + pas].second < timpX)
r += pas;
pas /= 2;
}
r++;
for(; r < ds[x].changes.size() && ds[x].changes[r].second <= v; r++){
pii change = ds[x].changes[r];
if(stX.find(change.first) != stX.end()){
stX.erase(change.first);
}else{
stX.insert(change.first);
}
}
r = -1, pas = (1 << 18);
while(pas){
if(r + pas < ds[y].changes.size() && ds[y].changes[r + pas].second < timpY)
r += pas;
pas /= 2;
}
r++;
for(; r < ds[y].changes.size() && ds[y].changes[r].second <= v; r++){
pii change = ds[y].changes[r];
if(stY.find(change.first) != stY.end()){
stY.erase(change.first);
}else{
stY.insert(change.first);
}
}
vector <int> parcurgere[2];
for(auto x : stX)
parcurgere[0].push_back(a[x]);
for(auto x : stY)
parcurgere[1].push_back(a[x]);
int minim = 1e9;
sort(parcurgere[0].begin(), parcurgere[0].end());
sort(parcurgere[1].begin(), parcurgere[1].end());
int i = 0, j = 0;
while(i < parcurgere[0].size() && j < parcurgere[1].size()){
minim = min(minim, abs(parcurgere[0][i] - parcurgere[1][j]));
if(parcurgere[0][i] < parcurgere[1][j])
i++;
else
j++;
}
return minim;
}
Compilation message
potion.cpp: In function 'int question(int, int, int)':
potion.cpp:75:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<BLOCK>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
75 | if(r + pas < ds[x].blocks.size() && ds[x].blocks[r + pas].time <= v)
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
potion.cpp:88:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<BLOCK>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
88 | if(r + pas < ds[y].blocks.size() && ds[y].blocks[r + pas].time <= v)
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
potion.cpp:100:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
100 | if(r + pas < ds[x].changes.size() && ds[x].changes[r + pas].second < timpX)
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
potion.cpp:105:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
105 | for(; r < ds[x].changes.size() && ds[x].changes[r].second <= v; r++){
| ~~^~~~~~~~~~~~~~~~~~~~~~
potion.cpp:115:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
115 | if(r + pas < ds[y].changes.size() && ds[y].changes[r + pas].second < timpY)
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
potion.cpp:120:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
120 | for(; r < ds[y].changes.size() && ds[y].changes[r].second <= v; r++){
| ~~^~~~~~~~~~~~~~~~~~~~~~
potion.cpp:137:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
137 | while(i < parcurgere[0].size() && j < parcurgere[1].size()){
| ~~^~~~~~~~~~~~~~~~~~~~~~
potion.cpp:137:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
137 | while(i < parcurgere[0].size() && j < parcurgere[1].size()){
| ~~^~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
10448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
10576 KB |
Output is correct |
2 |
Correct |
8 ms |
10704 KB |
Output is correct |
3 |
Correct |
7 ms |
10704 KB |
Output is correct |
4 |
Correct |
19 ms |
11592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
348 ms |
41676 KB |
Output is correct |
2 |
Correct |
363 ms |
41680 KB |
Output is correct |
3 |
Correct |
465 ms |
16984 KB |
Output is correct |
4 |
Correct |
2861 ms |
26608 KB |
Output is correct |
5 |
Correct |
855 ms |
34660 KB |
Output is correct |
6 |
Execution timed out |
3101 ms |
34376 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
343 ms |
41636 KB |
Output is correct |
2 |
Execution timed out |
3084 ms |
25236 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
12496 KB |
Output is correct |
2 |
Correct |
215 ms |
10960 KB |
Output is correct |
3 |
Correct |
437 ms |
10972 KB |
Output is correct |
4 |
Correct |
1716 ms |
11984 KB |
Output is correct |
5 |
Correct |
1695 ms |
12440 KB |
Output is correct |
6 |
Correct |
191 ms |
11600 KB |
Output is correct |
7 |
Correct |
1528 ms |
11152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
10448 KB |
Output is correct |
2 |
Correct |
8 ms |
10576 KB |
Output is correct |
3 |
Correct |
8 ms |
10704 KB |
Output is correct |
4 |
Correct |
7 ms |
10704 KB |
Output is correct |
5 |
Correct |
19 ms |
11592 KB |
Output is correct |
6 |
Correct |
348 ms |
41676 KB |
Output is correct |
7 |
Correct |
363 ms |
41680 KB |
Output is correct |
8 |
Correct |
465 ms |
16984 KB |
Output is correct |
9 |
Correct |
2861 ms |
26608 KB |
Output is correct |
10 |
Correct |
855 ms |
34660 KB |
Output is correct |
11 |
Execution timed out |
3101 ms |
34376 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |