# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1159352 | timoni | Chess Rush (CEOI20_chessrush) | C++20 | 0 ms | 0 KiB |
// made by Tima
// 2025 will be a golden year...
//BREAK YOUR LIMITS!!!!
#include "bits/stdc++.h"
#define pii pair <int,int>
#define all(x) x.begin() , x.end()
#define pb push_back
using namespace std;
const int N = 2e5 + 5 , M = 1e6 + 5;
const int mod = 1e9 + 7;
const int INF = 1e9;
int n,d,a[N],b[N],h[N],u,timer,root[M],val[N];
map <pii,int> mp;
struct node{
int l,r;
set <int> x;
}t[40 * N];
void build(int &v , int tl = 0 , int tr = u){
if(!v) v = ++ timer;
if(tl == tr){
return;
}
int tm = tl + tr >> 1;
build(t[v].l , tl , tm);
build(t[v].r , tm + 1 , tr);
}
void upd(int nv , int &v , int a , int b , int tl = 0 , int tr = u){
if(!v) v = ++ timer;
if(tl == tr){
t[v].x = t[nv].x;
if(b < 0){
b = abs(b);
t[v].x.erase(b);
}
else{
t[v].x.insert(b);
}
return;
}
int tm = tl + tr >> 1;
if(a <= tm){
t[v].r = t[nv].r;
upd(t[nv].l , t[v].l , a , b , tl , tm);
}
else{
t[v].l = t[nv].l;
upd(t[nv].r , t[v].r , a , b , tm + 1 , tr);
}
}
set <int> get(int v , int pos , int tl = 0 , int tr = u){
if(tl == tr){
return t[v].x;
}
int tm = tl + tr >> 1;
if(pos <= tm){
return get(t[v].l , pos , tl , tm);
}
else{
return get(t[v].r , pos , tm + 1 , tr);
}
}
void init(int nn , int D , int H[]){
n = nn , d = D;
for(int i = 0 ; i < nn ; i++){
h[i] = H[i];
}
}
void curseChanges(int U, int A[], int B[]){
u = U;
mp.clear();
int cnt = 0;
build(root[0]);
for(int i = 0 ; i < U ; i++){
a[i] = A[i] , b[i] = B[i];
mp[{min(a[i] , b[i]) , max(a[i] , b[i])}] ^= 1;
if(mp[{min(a[i] , b[i]) , max(a[i] , b[i])}]){
cnt++;
upd(root[cnt - 1] , root[cnt] , a[i] , b[i]);
cnt++;
upd(root[cnt - 1] , root[cnt] , b[i] , a[i]);
}
else{
cnt++;
upd(root[cnt - 1] , root[cnt] , a[i] , -b[i]);
cnt++;
upd(root[cnt - 1] , root[cnt] , b[i] , -a[i]);
}
val[i] = cnt;
}
}
int question(int X, int Y, int V){
int x = X , y = Y;
int ans = 1e9;
vector <int> q1 , q2;
if(!V){
return 1e9;
}
for(auto it : get(root[val[V - 1]] , X)){
q1.pb(h[it]);
// cout << it << ' ';
}
for(auto it : get(root[val[V - 1]] , Y)){
q2.pb(h[it]);
}
int j = 0;
sort(all(q1));
sort(all(q2));
for(int i = 0 ; i < q1.size() ; i++){
while(j < q2.size()){
ans = min(ans , abs(q1[i] - q2[j]));
if(q1[i] >= q2[j]){
j++;
}
else{
break;
}
}
}
return ans;
}
// signed main() {
// int N, D, U, Q;
// std::ios::sync_with_stdio(false); std::cin.tie(NULL);
// std::cin >> N >> D >> U >> Q;
//
// int *F = new int[N];
// for (int i=0; i<N; i++)
// std::cin >> F[i];
// init(N, D, F);
//
// int *A = new int[U], *B = new int[U];
// for (int i=0; i<U; i++) {
// std::cin >> A[i] >> B[i];
// }
// curseChanges(U, A, B);
//
// bool correct = true;
// for (int i=0; i<Q; i++) {
// int X,Y,V,CorrectAnswer;
// std::cin >> X >> Y >> V >> CorrectAnswer;
// int YourAnswer = question(X,Y,V);
// // cout << X << ' ' << Y << ' ' << V << '\n';
// if (YourAnswer != CorrectAnswer) {
// std::cout << "WA! Question: " << i << '\n'
// << "(X=" << X << ", Y=" << Y << ", V=" << V << ") \n"
// << "Your ans: " << YourAnswer << '\n'
// << "Correct Ans: " << CorrectAnswer << std::endl;
// correct = false;
// cout << "\n\n\n";
// } else {
// std::cerr << YourAnswer << " - OK" << std::endl;
// }
// }
//
// if (correct) {
// std::cout << "Correct." << std::endl;
// } else std::cout << "Incorrect." << std::endl;
// return 0;
// }