#include <iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <algorithm>
//#define debug(x) cerr << #x << " " << x << "\n"
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
const int bSize = 11;
const int bits = 17;
const int NMAX = 100000;
const int VMAX = NMAX * 89;
int a[NMAX], n;
int u;
int f[NMAX];
int changer = 0;
int par[NMAX];
int total = 0;
int nxt[NMAX * 1001];
int val[NMAX * 1001];
class lista{
public:
int cnt = 0;
int primul = 0;
int ultimul = 0;
void clear(){
cnt = 0;
primul = 0;
ultimul = 0;
}
void push_back(int x){
if(cnt == 0){
primul = ultimul = ++total;
}else{
nxt[ultimul] = ++total;
ultimul = total;
}
cnt++;
val[total] = x;
}
};
struct BLOCK {
int time;
lista v;
};
vector <BLOCK> blocks[NMAX];
vector <pii> changes[NMAX];
vector <int> vecini[NMAX];
void baga(int pt, int x, int cand) {
vecini[pt].push_back(x);
changes[pt].push_back({x, cand});
if(changes[pt].size() % bSize == 0) {
BLOCK nou;
changer++;
nou.v.clear();
nou.time = cand;
for(auto x : vecini[pt]) {
par[x] = 0;
}
for(auto x : vecini[pt]) {
par[x]++;
}
for(auto x : vecini[pt]) {
if(par[x] % 2 == 1 && f[x] != changer) {
nou.v.push_back(x);
f[x] = changer;
}
}
vecini[pt].clear(); // asta e confirmed?
int t = nou.v.primul;
while(t != 0){
vecini[pt].push_back(val[t]);
t = nxt[t];
}
blocks[pt].push_back(nou);
}
}
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;
baga(A[i], B[i], timp);
baga(B[i], A[i], timp);
}
}
bool cmp(int A, int B) {
if(a[A] != a[B])
return a[A] < a[B];
return A < B;
}
int impX[NMAX];
int impY[NMAX];
int intrebare;
vector <int> parcurgere[2];
int question(int x, int y, int v) {
int r = -1;
parcurgere[0].clear();
parcurgere[1].clear();
intrebare++;
int timpX = 0, timpY = 0;
int pas = (1 << 13), r1 = -1;
while(pas) {
if(r + pas < blocks[x].size() &&blocks[x][r + pas].time <= v)
r += pas;
if(r1 + pas < blocks[y].size() && blocks[y][r1 + pas].time <= v)
r1 += pas;
pas /= 2;
}
if(r != -1) {
timpX =blocks[x][r].time + 1;
int t = blocks[x][r].v.primul;
while(t != 0){
parcurgere[0].push_back(val[t]);
t = nxt[t];
}
}
if(r1 != -1) {
timpY = blocks[y][r1].time + 1;
int t = blocks[y][r].v.primul;
while(t != 0){
parcurgere[1].push_back(val[t]);
t = nxt[t];
}
}
r = -1, pas = (1 << bits), r1 = -1;
while(pas) {
if(r + pas < changes[x].size() && changes[x][r + pas].second < timpX)
r += pas;
if(r1 + pas < changes[y].size() && changes[y][r1 + pas].second < timpY)
r1 += pas;
pas /= 2;
}
r++;
for(; r < changes[x].size() && changes[x][r].second <= v; r++) {
pii change = changes[x][r];
parcurgere[0].push_back(change.first);
}
r1++;
for(; r1 < changes[y].size() && changes[y][r1].second <= v; r1++) {
pii change = changes[y][r1];
parcurgere[1].push_back(change.first);
}
if(!parcurgere[0].size() || !parcurgere[1].size()) return 1e9;
sort(parcurgere[0].begin(), parcurgere[0].end(), cmp);
sort(parcurgere[1].begin(), parcurgere[1].end(), cmp);
for(auto x : parcurgere[0]) {
impX[x] = 0;
}
for(auto x : parcurgere[0]) {
impX[x]++;
}
for(auto x : parcurgere[1]) {
impY[x] = 0;
}
for(auto x : parcurgere[1]) {
impY[x]++;
}
int minim = 1e9;
int j = 0, i = 0;
while(i < parcurgere[0].size() && j < parcurgere[1].size()) {
if(impX[parcurgere[0][i]] % 2 == 0) {
i++;
continue;
}
if(impY[parcurgere[1][j]] % 2 == 0) {
j++;
continue;
}
minim = min(minim, abs(a[parcurgere[0][i]] - a[parcurgere[1][j]]));
if(a[parcurgere[0][i]] < a[parcurgere[1][j]])
i++;
else
j++;
}
return minim;
}
Compilation message
potion.cpp: In function 'int question(int, int, int)':
potion.cpp:125:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<BLOCK>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
125 | if(r + pas < blocks[x].size() &&blocks[x][r + pas].time <= v)
| ~~~~~~~~^~~~~~~~~~~~~~~~~~
potion.cpp:127:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<BLOCK>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
127 | if(r1 + pas < blocks[y].size() && blocks[y][r1 + pas].time <= v)
| ~~~~~~~~~^~~~~~~~~~~~~~~~~~
potion.cpp:149: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]
149 | if(r + pas < changes[x].size() && changes[x][r + pas].second < timpX)
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~
potion.cpp:151:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
151 | if(r1 + pas < changes[y].size() && changes[y][r1 + pas].second < timpY)
| ~~~~~~~~~^~~~~~~~~~~~~~~~~~~
potion.cpp:156: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]
156 | for(; r < changes[x].size() && changes[x][r].second <= v; r++) {
| ~~^~~~~~~~~~~~~~~~~~~
potion.cpp:161:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
161 | for(; r1 < changes[y].size() && changes[y][r1].second <= v; r1++) {
| ~~~^~~~~~~~~~~~~~~~~~~
potion.cpp:182:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
182 | while(i < parcurgere[0].size() && j < parcurgere[1].size()) {
| ~~^~~~~~~~~~~~~~~~~~~~~~
potion.cpp:182:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
182 | while(i < parcurgere[0].size() && j < parcurgere[1].size()) {
| ~~^~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
7376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7376 KB |
Output is correct |
2 |
Correct |
4 ms |
7376 KB |
Output is correct |
3 |
Correct |
5 ms |
7376 KB |
Output is correct |
4 |
Correct |
17 ms |
8936 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
149 ms |
21568 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
144 ms |
21728 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
8144 KB |
Output is correct |
2 |
Incorrect |
7 ms |
8144 KB |
Incorrect |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
7376 KB |
Output is correct |
2 |
Correct |
4 ms |
7376 KB |
Output is correct |
3 |
Correct |
4 ms |
7376 KB |
Output is correct |
4 |
Correct |
5 ms |
7376 KB |
Output is correct |
5 |
Correct |
17 ms |
8936 KB |
Output is correct |
6 |
Incorrect |
149 ms |
21568 KB |
Incorrect |
7 |
Halted |
0 ms |
0 KB |
- |