#include<iostream>
#include<set>
#include<vector>
#include<unordered_set>
using namespace std;
typedef long long ll;
// time travelling multiset
class TTMS{
vector<multiset<int>>v;
public:
TTMS(){
v={{}};
}
void add_new_day(){
v.push_back(v.back());
}
void insert(int el){
v.back().insert(el);
}
void remove(int el){
v.back().erase(v.back().find(el));
}
vector<int> get(int day){
return {v[day].begin(),v[day].end()};
}
};
int get_closest(vector<int>a,vector<int>b){
int res=1e9;
for(int i:a)
for(int j:b){
res=min(res,abs(i-j));
}
return res;
}
int n;
int heights[100000];
TTMS ttms[100000];
void init(int N, int D, int H[]) {
n=N;
for(int i=0;i<n;i++)
heights[i]=H[i];
}
ll to(int a,int b){
if(a<b)
swap(a,b);
return a+((ll)b<<32);
}
void curseChanges(int U, int A[], int B[]) {
unordered_set<ll>conns;
for(int day=0;day<U;day++){
for(int i=0;i<n;i++)
ttms[i].add_new_day();
int a=A[day],b=B[day];
ll conn=to(a,b);
if(conns.find(conn)==conns.end()){
conns.insert(conn);
ttms[a].insert(b);
ttms[b].insert(a);
}else{
conns.erase(conn);
ttms[a].remove(b);
ttms[b].remove(a);
}
}
}
int question(int x, int y, int v) {
vector<int>a=ttms[x].get(v);
vector<int>b=ttms[y].get(v);
for(int&i:a)
i=heights[i];
for(int&i:b)
i=heights[i];
return get_closest(a,b);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
8912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
124 ms |
103612 KB |
Output is correct |
2 |
Correct |
143 ms |
104200 KB |
Output is correct |
3 |
Correct |
130 ms |
103704 KB |
Output is correct |
4 |
Runtime error |
281 ms |
262144 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
277 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
263 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
238 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
8912 KB |
Output is correct |
2 |
Correct |
124 ms |
103612 KB |
Output is correct |
3 |
Correct |
143 ms |
104200 KB |
Output is correct |
4 |
Correct |
130 ms |
103704 KB |
Output is correct |
5 |
Runtime error |
281 ms |
262144 KB |
Execution killed with signal 9 |
6 |
Halted |
0 ms |
0 KB |
- |