#include<iostream>
#include<set>
#include<vector>
#include<unordered_set>
using namespace std;
typedef long long ll;
const int C=32;
// time travelling multiset
class TTMS{
vector<int>days;
vector<pair<int,int>>changes;
vector<vector<int>>checkpoints;
multiset<int>curr_set;
int curr_day=0;
void add_day(){
days.push_back(curr_day);
if(checkpoints.size()*C<days.size())
checkpoints.push_back({curr_set.begin(),curr_set.end()});
}
public:
TTMS(){
checkpoints={};
}
void add_new_day(int day){
curr_day=day;
}
void insert(int el){
add_day();
curr_set.insert(el);
changes.push_back({el,1});
}
void remove(int el){
add_day();
curr_set.erase(curr_set.find(el));
changes.push_back({el,-1});
}
vector<int> get(int day){
multiset<int>s;
int l=0,r=(int)days.size();
while(l<r-1){
int m=(l+r)/2;
if(days[m]<=day)
l=m;
else
r=m;
}
int idx=l;
if(idx/C>=(int)checkpoints.size())
s=curr_set;
else
s={checkpoints[idx/C].begin(),checkpoints[idx/C].end()};
for(int i=idx/C*C;i<(int)changes.size();i++){
if(days[i]>day)
break;
if(changes[i].second==1)
s.insert(changes[i].first);
else if(changes[i].second==-1)
s.erase(s.find(changes[i].first));
}
return{s.begin(),s.end()};
}
};
int get_closest(vector<int>a,vector<int>b){
int res=1e9;
int i=0,j=0;
while(i<(int)a.size()&&j<(int)b.size()){
res=min(res,abs(a[i]-b[j]));
if(i<(int)a.size()&&a[i]<=b[j])
i++;
else if(j<(int)b.size()&&b[j]<=a[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++){
int a=A[day],b=B[day];
ll conn=to(a,b);
ttms[a].add_new_day(day+1);
ttms[b].add_new_day(day+1);
if(conns.find(conn)==conns.end()){
conns.insert(conn);
ttms[a].insert(heights[b]);
ttms[b].insert(heights[a]);
}else{
conns.erase(conn);
ttms[a].remove(heights[b]);
ttms[b].remove(heights[a]);
}
}
}
int question(int x, int y, int v) {
vector<int>a=ttms[x].get(v);
vector<int>b=ttms[y].get(v);
return get_closest(a,b);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
12752 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
13008 KB |
Output is correct |
2 |
Correct |
7 ms |
13008 KB |
Output is correct |
3 |
Correct |
7 ms |
13008 KB |
Output is correct |
4 |
Correct |
16 ms |
13896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
386 ms |
55268 KB |
Output is correct |
2 |
Correct |
391 ms |
55376 KB |
Output is correct |
3 |
Correct |
202 ms |
21344 KB |
Output is correct |
4 |
Correct |
1426 ms |
40912 KB |
Output is correct |
5 |
Correct |
633 ms |
51316 KB |
Output is correct |
6 |
Execution timed out |
3024 ms |
43384 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
375 ms |
55328 KB |
Output is correct |
2 |
Correct |
2175 ms |
34056 KB |
Output is correct |
3 |
Correct |
1576 ms |
39008 KB |
Output is correct |
4 |
Execution timed out |
3043 ms |
43220 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
15124 KB |
Output is correct |
2 |
Correct |
123 ms |
13520 KB |
Output is correct |
3 |
Correct |
191 ms |
13320 KB |
Output is correct |
4 |
Correct |
705 ms |
14544 KB |
Output is correct |
5 |
Correct |
1112 ms |
15124 KB |
Output is correct |
6 |
Correct |
130 ms |
14544 KB |
Output is correct |
7 |
Correct |
623 ms |
13736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
12752 KB |
Output is correct |
2 |
Correct |
7 ms |
13008 KB |
Output is correct |
3 |
Correct |
7 ms |
13008 KB |
Output is correct |
4 |
Correct |
7 ms |
13008 KB |
Output is correct |
5 |
Correct |
16 ms |
13896 KB |
Output is correct |
6 |
Correct |
386 ms |
55268 KB |
Output is correct |
7 |
Correct |
391 ms |
55376 KB |
Output is correct |
8 |
Correct |
202 ms |
21344 KB |
Output is correct |
9 |
Correct |
1426 ms |
40912 KB |
Output is correct |
10 |
Correct |
633 ms |
51316 KB |
Output is correct |
11 |
Execution timed out |
3024 ms |
43384 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |