# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1043073 | beaconmc | The Potion of Great Power (CEOI20_potion) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include <bits/stdc++.h>
typedef int ll;
#define FOR(i,x,y) for(ll i=x; i<y; i++)
#define FORNEG(i,x,y) for(ll i=x; i>y; i--)
using namespace std;
vector<unordered_set<ll>> edges[101];
vector<ll> h;
vector<ll> a;
vector<ll> b;
void init(int N, int D, int H[]) {
FOR(i,0,N) h.push_back(H[i]);
}
void curseChanges(int U, int A[], int B[]) {
vector<unordered_set<ll>> tempedges(10001);
FOR(i,0,U){
a.push_back(A[i]);
b.push_back(B[i]);
if (tempedges[A[i]].count(B[i])) tempedges[A[i]].erase(B[i]);
else tempedges[A[i]].insert(B[i]);
if (tempedges[B[i]].count(A[i])) tempedges[B[i]].erase(A[i]);
else tempedges[B[i]].insert(A[i]);
if (i%100==0) edges[i/100] = tempedges;
}
}
int mindiff(unordered_set<ll>&a, unordered_set<ll>&b){
ll ans = 1000000000;
vector<vector<ll>> A,B;
for (auto&i : a) A.push_back({h[i], 0});
for (auto&i : b) A.push_back({h[i], 1});
if (A.size()==0) return ans;
sort(A.begin(), A.end());
FOR(i,0,A.size()-1){
if (A[i][1] != A[i+1][1]) ans = min(ans, abs(A[i][0]-A[i+1][0]));
}
return ans;
}
int question(int x, int y, int v) {
v--;
unordered_set<ll> X=edges[v/100][x];
unordered_set<ll> Y=edges[v/100][y];
FOR(i,(v/100)*100+1, v+1){
if (a[i] == x){
if (X.find(b[i]) != X.end()) X.erase(b[i]);
else X.insert(b[i]);
}
if (a[i] == y){
if (Y.find(b[i]) != Y.end()) Y.erase(b[i]);
else Y.insert(b[i]);
}
if (b[i] == x){
if (X.find(a[i]) != X.end()) X.erase(a[i]);
else X.insert(a[i]);
}
if (b[i] == y){
if (Y.find(a[i]) != Y.end()) Y.erase(a[i]);
else Y.insert(a[i]);
}
}
return mindiff(X,Y);
}
void init(int N, int D, int F[]);
void curseChanges(int U, int A[], int B[]);
int question(int X, int Y, int V);
int 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);
if (YourAnswer != CorrectAnswer) {
std::cout << "WA! Question: " << i
<< " (X=" << X << ", Y=" << Y << ", V=" << V << ") "
<< "Your answer: " << YourAnswer
<< " Correct Answer: " << CorrectAnswer << std::endl;
correct = false;
} else {
std::cerr << YourAnswer << " - OK" << std::endl;
}
}
if (correct) {
std::cout << "Correct." << std::endl;
} else std::cout << "Incorrect." << std::endl;
return 0;
}