#include <bits/stdc++.h>
//#pragma GCC target("sse,sse2,sse4,avx2")
//#pragma GCC optimize("unroll-loops,O2")
#define rep(i,l,r) for (int i = l; i < r; i++)
#define repr(i,r,l) for (int i = r; i >= l; i--)
#define X first
#define Y second
#define all(x) (x).begin() , (x).end()
#define pb push_back
#define endl '\n'
#define debug(x) cerr << #x << " : " << x << endl;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pll;
constexpr int N = 2e5+10,mod = 1e9+7,inf = 1e9+10,sq = 1000;
inline int mkay(int a,int b){
if (a+b >= mod) return a+b-mod;
if (a+b < 0) return a+b+mod;
return a+b;
}
inline int poww(int a,int k){
if (k < 0) return 0;
int z = 1;
while (k){
if (k&1) z = 1ll*z*a%mod;
a = 1ll*a*a%mod;
k >>= 1;
}
return z;
}
int n,d,h[N],a[N],b[N],u;
vector<set<pll> > st[N];
set<pll> st1,st2;
vector<int> ti[N],v1;
void init(int N, int D, int H[]) {
n = N;
d = D;
rep(i,0,n) h[i] = H[i];
}
void curseChanges(int U, int A[], int B[]) {
u = U;
rep(i,0,n){
st[i].resize(1);
ti[i].pb(0);
}
rep(i,0,U){
a[i+1] = A[i];
b[i+1] = B[i];
if ((i+1)%sq == 0){
int l = i-sq+1;
rep(k,l,i+1){
if (ti[A[k]].back() != i+1){
ti[A[k]].pb(i+1);
st[A[k]].pb(st[A[k]].back());
}
if (ti[B[k]].back() != i+1){
ti[B[k]].pb(i+1);
st[B[k]].pb(st[B[k]].back());
}
int sz1 = st[A[k]].size(),sz2 = st[B[k]].size();;
if (st[A[k]][sz1-1].find({h[B[k]],B[k]}) != st[A[k]][sz1-1].end()){
st[A[k]][sz1-1].erase({h[B[k]],B[k]});
st[B[k]][sz2-1].erase({h[A[k]],A[k]});
}
else{
st[A[k]][sz1-1].insert({h[B[k]],B[k]});
st[B[k]][sz2-1].insert({h[A[k]],A[k]});
}
}
}
}
}
int question(int x, int y, int v) {
if (!v) return 1000000000;
int dd = 0;
if (v >= sq){
int j = v/sq;
dd = j*sq;
int ind = upper_bound(all(ti[x]),dd)-ti[x].begin()-1;
st1 = st[x][ind];
ind = upper_bound(all(ti[y]),dd)-ti[y].begin()-1;
st2 = st[y][ind];
}
else{
st1.clear();
st2.clear();
}
rep(i,dd+1,v+1){
if (a[i] == x){
if (st1.find({h[b[i]],b[i]}) != st1.end())
st1.erase({h[b[i]],b[i]});
else
st1.insert({h[b[i]],b[i]});
}
if (a[i] == y){
if (st2.find({h[b[i]],b[i]}) != st2.end())
st2.erase({h[b[i]],b[i]});
else
st2.insert({h[b[i]],b[i]});
}
if (b[i] == x){
if (st1.find({h[a[i]],a[i]}) != st1.end())
st1.erase({h[a[i]],a[i]});
else
st1.insert({h[a[i]],a[i]});
}
if (b[i] == y){
if (st2.find({h[a[i]],a[i]}) != st2.end())
st2.erase({h[a[i]],a[i]});
else
st2.insert({h[a[i]],a[i]});
}
}
if (st1.empty() || st2.empty()) return 1000000000;
v1.clear();
int po = 0,ans = 1000000000;
for (pll x : st1) v1.pb(x.X);
int sz = v1.size();
for (pll x : st2){
while(po < sz && v1[po] <= x.X) po++;
if (po) ans = min(ans,x.X-v1[po-1]);
if (po < sz) ans = min(ans,v1[po]-x.X);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
9936 KB |
Output is correct |
2 |
Correct |
7 ms |
9936 KB |
Output is correct |
3 |
Correct |
9 ms |
9936 KB |
Output is correct |
4 |
Correct |
30 ms |
20092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
526 ms |
108920 KB |
Output is correct |
2 |
Correct |
508 ms |
108988 KB |
Output is correct |
3 |
Correct |
175 ms |
33224 KB |
Output is correct |
4 |
Runtime error |
289 ms |
262144 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
542 ms |
108992 KB |
Output is correct |
2 |
Execution timed out |
3043 ms |
58584 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
78 ms |
13904 KB |
Output is correct |
2 |
Correct |
182 ms |
11416 KB |
Output is correct |
3 |
Correct |
1710 ms |
11116 KB |
Output is correct |
4 |
Correct |
973 ms |
13336 KB |
Output is correct |
5 |
Correct |
926 ms |
13872 KB |
Output is correct |
6 |
Correct |
163 ms |
15184 KB |
Output is correct |
7 |
Correct |
2087 ms |
11904 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9680 KB |
Output is correct |
2 |
Correct |
9 ms |
9936 KB |
Output is correct |
3 |
Correct |
7 ms |
9936 KB |
Output is correct |
4 |
Correct |
9 ms |
9936 KB |
Output is correct |
5 |
Correct |
30 ms |
20092 KB |
Output is correct |
6 |
Correct |
526 ms |
108920 KB |
Output is correct |
7 |
Correct |
508 ms |
108988 KB |
Output is correct |
8 |
Correct |
175 ms |
33224 KB |
Output is correct |
9 |
Runtime error |
289 ms |
262144 KB |
Execution killed with signal 9 |
10 |
Halted |
0 ms |
0 KB |
- |