# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
965299 | 2024-04-18T09:56:20 Z | pcc | Cell Automaton (JOI23_cell) | C++17 | 157 ms | 62452 KB |
#include <bits/stdc++.h> using namespace std; #define pii pair<int,int> #define fs first #define sc second #define ll long long const int mxn = 1e5+10; int N,Q; struct D{ ll t,tp,a,b; D(){} D(ll tt,ll ttp,ll aa,ll bb = 0):a(aa),b(bb),t(tt),tp(ttp){} bool operator<(D b)const{ return t==b.t?tp<b.tp:t<b.t; } }; struct DSU{ int dsu[mxn],sz[mxn]; int cc; DSU(){} void init(int n){ for(int i = 0;i<=n;i++){ dsu[i] = i,sz[i] = 1; cc++; } cc = n; return; } int root(int k){ return k == dsu[k]?k:dsu[k] = root(dsu[k]); } void onion(int a,int b){ a = root(a),b = root(b); if(a == b)return; if(sz[a]<sz[b])swap(a,b); cc--; dsu[b] = a; sz[a] += sz[b]; return; } }; DSU dsu; vector<D> all; int arr[mxn]; ll ans[mxn]; ll sum = 0; int main(){ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin>>N>>Q; for(int i = 0;i<N;i++){ cin>>arr[i]>>arr[i]; } sort(arr,arr+N); dsu.init(N); for(int i = 1;i<N;i++){ if((arr[i]-arr[i-1])&1){ all.push_back(D(arr[i]-arr[i-1],1,(arr[i]-arr[i-1])+1)); all.push_back(D(arr[i]-arr[i-1],2,i-1,i)); all.push_back(D(arr[i]-arr[i-1]+1,1,(arr[i]-arr[i-1])-1)); } else{ all.push_back(D(arr[i]-arr[i-1],1,arr[i]-arr[i-1]+1)); all.push_back(D(arr[i]-arr[i-1],2,i-1,i)); all.push_back(D(arr[i]-arr[i-1]+1,1,arr[i]-arr[i-1]-1)); } } for(int i = 0;i<Q;i++){ ll k; cin>>k; all.push_back(D(k,3,i)); } sort(all.begin(),all.end()); ll nowt = 0; for(auto &i:all){ sum += (i.t-nowt)*4*dsu.cc; nowt = i.t; if(i.tp == 3){ if(!i.t)ans[i.a] = N; else ans[i.a] = sum; } else if(i.tp == 1)sum -= i.a; else dsu.onion(i.a,i.b); } for(int i = 0;i<Q;i++)cout<<ans[i]<<'\n'; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 62 ms | 20928 KB | Output is correct |
2 | Correct | 70 ms | 20160 KB | Output is correct |
3 | Correct | 57 ms | 20312 KB | Output is correct |
4 | Correct | 60 ms | 21016 KB | Output is correct |
5 | Correct | 60 ms | 21136 KB | Output is correct |
6 | Correct | 57 ms | 20416 KB | Output is correct |
7 | Correct | 59 ms | 20416 KB | Output is correct |
8 | Correct | 1 ms | 348 KB | Output is correct |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Correct | 1 ms | 740 KB | Output is correct |
11 | Correct | 58 ms | 21304 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 62 ms | 20928 KB | Output is correct |
2 | Correct | 70 ms | 20160 KB | Output is correct |
3 | Correct | 57 ms | 20312 KB | Output is correct |
4 | Correct | 60 ms | 21016 KB | Output is correct |
5 | Correct | 60 ms | 21136 KB | Output is correct |
6 | Correct | 57 ms | 20416 KB | Output is correct |
7 | Correct | 59 ms | 20416 KB | Output is correct |
8 | Correct | 1 ms | 348 KB | Output is correct |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Correct | 1 ms | 740 KB | Output is correct |
11 | Correct | 58 ms | 21304 KB | Output is correct |
12 | Runtime error | 157 ms | 62452 KB | Execution killed with signal 11 |
13 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 860 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 860 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |