#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define ff first
#define ss second
ll ttt;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const ll MAXN = 1e5 + 7;
int n;
int a[MAXN];
vector<pair<int, int>>q[MAXN];
vector<int>vi[MAXN];
vector<set<int>>v[MAXN];
set<int>curv[MAXN];
int T;
void init(int N, int D, int H[]) {
n = N;
set<int>empty;
empty.clear();
for (int i = 0; i < n; i++) {
a[i] = H[i];
v[i].push_back(empty);
vi[i].push_back(-1);
}
T = 100;
}
void curseChanges(int U, int A[], int B[]) {
for(int i=0;i<U;i++){
if(curv[A[i]].find(B[i])!=curv[A[i]].end()){
// A[i]
q[A[i]].push_back({i, -(B[i]+1)});
curv[A[i]].erase(B[i]);
// B[i]
q[B[i]].push_back({i, -(A[i]+1)});
curv[B[i]].erase(A[i]);
}
else{
// A[i]
q[A[i]].push_back({i, (B[i]+1)});
curv[A[i]].insert(B[i]);
// B[i]
q[B[i]].push_back({i, (A[i]+1)});
curv[B[i]].insert(A[i]);
}
if(q[A[i]].size()%T==0){
v[A[i]].push_back(curv[A[i]]);
vi[A[i]].push_back(i);
}
if(q[B[i]].size()%T==0){
v[B[i]].push_back(curv[B[i]]);
vi[B[i]].push_back(i);
}
}
}
set<int>cx,cy;
vector<int>vx,vy;
int question(int x, int y, int u) {
cx.clear(), cy.clear(), vx.clear(), vy.clear();
// x
auto it=lower_bound(vi[x].begin(),vi[x].end(),u);
it--;
int ind=it-vi[x].begin();
int day=*it;
cx=v[x][ind];
auto it2=upper_bound(q[x].begin(),q[x].end(),make_pair(day, int(1e9)));
while(it2!=q[x].end()&&(*it2).ff<u){
if((*it2).ss>0){
cx.insert((*it2).ss-1);
}
else{
cx.erase(-(*it2).ss-1);
}
it2++;
}
for(int i:cx){
vx.push_back(a[i]);
}
// y
it=lower_bound(vi[y].begin(),vi[y].end(),u);
it--;
ind=it-vi[y].begin();
day=*it;
cy=v[y][ind];
it2=upper_bound(q[y].begin(),q[y].end(),make_pair(day, int(1e9)));
while(it2!=q[y].end()&&(*it2).ff<u){
if((*it2).ss>0){
cy.insert((*it2).ss-1);
}
else{
cy.erase(-(*it2).ss-1);
}
it2++;
}
for(int i:cy){
vy.push_back(a[i]);
}
// finding the closest
sort(vx.begin(),vx.end());
sort(vy.begin(),vy.end());
int ix=0,iy=0;
int ans=1e9;
while(ix<vx.size()&&iy<vy.size()){
ans=min(ans,abs(vx[ix]-vy[iy]));
if(vx[ix]<=vy[iy])ix++;
else iy++;
}
return ans;
}
// 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;
// }
Compilation message
potion.cpp: In function 'int question(int, int, int)':
potion.cpp:120:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
120 | while(ix<vx.size()&&iy<vy.size()){
| ~~^~~~~~~~~~
potion.cpp:120:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
120 | while(ix<vx.size()&&iy<vy.size()){
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
12012 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
12312 KB |
Output is correct |
2 |
Correct |
7 ms |
12236 KB |
Output is correct |
3 |
Correct |
7 ms |
12240 KB |
Output is correct |
4 |
Correct |
30 ms |
22296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
306 ms |
49260 KB |
Output is correct |
2 |
Correct |
269 ms |
49220 KB |
Output is correct |
3 |
Correct |
387 ms |
29316 KB |
Output is correct |
4 |
Correct |
1961 ms |
50760 KB |
Output is correct |
5 |
Correct |
599 ms |
38728 KB |
Output is correct |
6 |
Execution timed out |
3021 ms |
68040 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
259 ms |
49292 KB |
Output is correct |
2 |
Correct |
2110 ms |
65796 KB |
Output is correct |
3 |
Correct |
1303 ms |
51172 KB |
Output is correct |
4 |
Correct |
2195 ms |
67864 KB |
Output is correct |
5 |
Correct |
420 ms |
50776 KB |
Output is correct |
6 |
Correct |
2428 ms |
67976 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
52 ms |
14416 KB |
Output is correct |
2 |
Correct |
187 ms |
13392 KB |
Output is correct |
3 |
Correct |
361 ms |
13392 KB |
Output is correct |
4 |
Correct |
1154 ms |
14544 KB |
Output is correct |
5 |
Correct |
1090 ms |
14776 KB |
Output is correct |
6 |
Correct |
140 ms |
13392 KB |
Output is correct |
7 |
Correct |
983 ms |
14028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
12012 KB |
Output is correct |
2 |
Correct |
7 ms |
12312 KB |
Output is correct |
3 |
Correct |
7 ms |
12236 KB |
Output is correct |
4 |
Correct |
7 ms |
12240 KB |
Output is correct |
5 |
Correct |
30 ms |
22296 KB |
Output is correct |
6 |
Correct |
306 ms |
49260 KB |
Output is correct |
7 |
Correct |
269 ms |
49220 KB |
Output is correct |
8 |
Correct |
387 ms |
29316 KB |
Output is correct |
9 |
Correct |
1961 ms |
50760 KB |
Output is correct |
10 |
Correct |
599 ms |
38728 KB |
Output is correct |
11 |
Execution timed out |
3021 ms |
68040 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |