#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>
pii delta[4] ={{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
vector<pii> find_adj(pii pos){
vector<pii> res;
for(int i = 0; i<4; i++){
res.push_back({pos.first+delta[i].first, pos.second + delta[i].second});
}
return res;
}
map<pii, int> next(map<pii, int> cur){
map<pii, int> res;
for(auto e: cur){
if(e.second >0){
res[e.first] =e.second-1;
}
}
for(auto e: cur){
if(e.second ==2){
for(auto ee: find_adj(e.first)){
if(res.find(ee)==res.end()){
res[ee] = 2;
}
}
}
}
return res;
}
const int sz= 10;
void display(map<pii, int>&m){
for(int i = -sz; i<=sz; i++){
for(int j = -sz; j<=sz; j++){
if(m.find({i, j})!=m.end()){
//cout<<m[{i, j}];
}
else{
//cout<<"0";
}
}
//cout<<endl;
}
//cout<<endl;
}
struct DSU{
vector<int> dsu;
vector<int> sz;
vector<pii> interval;
vector<int> pos;
int ca =0;
int cb= 0;
void init(int len, vector<int>&p){
dsu.resize(len);
sz.resize(len);
for(int i = 0; i<len; i++){
dsu[i] = i;
sz[i] =1;
}
interval.resize(len);
pos = p;
for(int i = 0; i<len; i++){
interval[i] = {pos[i], pos[i]};
}
ca= len*4;
}
int c(int u){
if(dsu[u] == u){
return u;
}
int r= c(dsu[u]);
dsu[u]= r;
return r;
}
int merge(int a, int b, int t){
//cout<<a<<" "<<b<<" "<<endl;
a= c(a);
b= c(b);
//cout<<"before "<<ca<<"x + "<<cb<<endl;
ca-= 2;
cb-=-2;
ca -= 4;
cb -= 2*(interval[a].second-interval[a].first+1) + 2*(interval[b].second-interval[b].first+1);
if(sz[a]<sz[b]){
swap(a, b);
}
dsu[b] = a;
sz[a]+=b;
interval[a] = {min(interval[a].first, interval[b].first), max(interval[a].second, interval[b].second)};
ca +=2;
cb += 2*(interval[a].second-interval[a].first+1);
//cout<<"after "<<ca<<"x + "<<cb<<endl;
return t-1;
}
};
signed main(){
int n, q;
cin>>n>>q;
vector<int> pos;
map<pii, int> cur;
bool diag= true;
for(int i = 0; i<n; i++){
int x, y;
cin>>x>>y;
pos.push_back(x);
cur[{x, y}] = 2;
if(x!=y){
diag= false;
}
}
if(diag){
sort(pos.begin(), pos.end());
vector<pii> distances;
map<int, pair<int, pii>> formulas;
DSU ds;
ds.init(n, pos);
int kept= 0;
for(int i = 0; i<n-1; i++){
distances.push_back({pos[i+1]-pos[i], i});
//cout<<distances[i].first<<" "<<distances[i].second<<endl;
}
sort(distances.begin(), distances.end());
int cur_t= -1;
for(int i = 0;i<n-1; i++){
if(distances[i].first != cur_t){
formulas[cur_t] = {kept, {ds.ca, ds.cb}};
kept= 0;
cur_t =distances[i].first;
}
kept += ds.merge(distances[i].second, distances[i].second+1, distances[i].first);
}
formulas[cur_t] = {kept, {ds.ca, ds.cb}};
for(int i = 0; i<q; i++){
int t;
cin>>t;
if(t==0){
cout<<n<<endl;
continue;
}
auto it = --formulas.upper_bound(t);
auto e= *(it);
//cout<<"at time "<<t<<" formula "<<e.second.second.first<<" "<<e.second.second.second<<" +("<<e.second.first<<endl;
int res= 0;
if(it->first == t){
res += it->second.first;
}
res += it->second.second.first*t + it->second.second.second;
cout<<res<<endl;
}
}
else{
vector<int> ans(1000+1, -1);
int r;
for(int steps= 0; steps<1000+1; steps++){
r=0;
for(auto e: cur){
if(e.second ==2){
r++;
}
}
ans[steps] = r;
cur = next(cur);
}
int max_s= 0;
for(int i = 0; i<q; i++){
int steps= 0;
cin>>steps;
cout<<ans[steps]<<endl;
}
}
}
Compilation message
cell.cpp: In function 'int main()':
cell.cpp:165:18: warning: variable 'e' set but not used [-Wunused-but-set-variable]
165 | auto e= *(it);
| ^
cell.cpp:192:13: warning: unused variable 'max_s' [-Wunused-variable]
192 | int max_s= 0;
| ^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1486 ms |
2796 KB |
Output is correct |
2 |
Correct |
1581 ms |
2644 KB |
Output is correct |
3 |
Correct |
1701 ms |
2900 KB |
Output is correct |
4 |
Correct |
1745 ms |
2968 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1803 ms |
3044 KB |
Output is correct |
9 |
Correct |
1791 ms |
3016 KB |
Output is correct |
10 |
Correct |
1766 ms |
2984 KB |
Output is correct |
11 |
Correct |
1730 ms |
2840 KB |
Output is correct |
12 |
Correct |
1808 ms |
2736 KB |
Output is correct |
13 |
Correct |
1810 ms |
3232 KB |
Output is correct |
14 |
Correct |
1803 ms |
2724 KB |
Output is correct |
15 |
Correct |
1743 ms |
3156 KB |
Output is correct |
16 |
Correct |
1435 ms |
2600 KB |
Output is correct |
17 |
Correct |
1453 ms |
2640 KB |
Output is correct |
18 |
Correct |
1462 ms |
3380 KB |
Output is correct |
19 |
Correct |
1421 ms |
2496 KB |
Output is correct |
20 |
Correct |
1442 ms |
2492 KB |
Output is correct |
21 |
Correct |
1429 ms |
2576 KB |
Output is correct |
22 |
Correct |
1442 ms |
2692 KB |
Output is correct |
23 |
Correct |
1440 ms |
2836 KB |
Output is correct |
24 |
Correct |
1436 ms |
2644 KB |
Output is correct |
25 |
Correct |
1444 ms |
2836 KB |
Output is correct |
26 |
Correct |
1448 ms |
2860 KB |
Output is correct |
27 |
Correct |
1471 ms |
3100 KB |
Output is correct |
28 |
Correct |
1448 ms |
2584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1486 ms |
2796 KB |
Output is correct |
2 |
Correct |
1581 ms |
2644 KB |
Output is correct |
3 |
Correct |
1701 ms |
2900 KB |
Output is correct |
4 |
Correct |
1745 ms |
2968 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1803 ms |
3044 KB |
Output is correct |
9 |
Correct |
1791 ms |
3016 KB |
Output is correct |
10 |
Correct |
1766 ms |
2984 KB |
Output is correct |
11 |
Correct |
1730 ms |
2840 KB |
Output is correct |
12 |
Correct |
1808 ms |
2736 KB |
Output is correct |
13 |
Correct |
1810 ms |
3232 KB |
Output is correct |
14 |
Correct |
1803 ms |
2724 KB |
Output is correct |
15 |
Correct |
1743 ms |
3156 KB |
Output is correct |
16 |
Correct |
1435 ms |
2600 KB |
Output is correct |
17 |
Correct |
1453 ms |
2640 KB |
Output is correct |
18 |
Correct |
1462 ms |
3380 KB |
Output is correct |
19 |
Correct |
1421 ms |
2496 KB |
Output is correct |
20 |
Correct |
1442 ms |
2492 KB |
Output is correct |
21 |
Correct |
1429 ms |
2576 KB |
Output is correct |
22 |
Correct |
1442 ms |
2692 KB |
Output is correct |
23 |
Correct |
1440 ms |
2836 KB |
Output is correct |
24 |
Correct |
1436 ms |
2644 KB |
Output is correct |
25 |
Correct |
1444 ms |
2836 KB |
Output is correct |
26 |
Correct |
1448 ms |
2860 KB |
Output is correct |
27 |
Correct |
1471 ms |
3100 KB |
Output is correct |
28 |
Correct |
1448 ms |
2584 KB |
Output is correct |
29 |
Correct |
1497 ms |
2596 KB |
Output is correct |
30 |
Correct |
2490 ms |
3372 KB |
Output is correct |
31 |
Correct |
3912 ms |
4432 KB |
Output is correct |
32 |
Correct |
6949 ms |
132292 KB |
Output is correct |
33 |
Correct |
2 ms |
348 KB |
Output is correct |
34 |
Correct |
2 ms |
348 KB |
Output is correct |
35 |
Correct |
2 ms |
348 KB |
Output is correct |
36 |
Correct |
1440 ms |
2680 KB |
Output is correct |
37 |
Correct |
1449 ms |
2484 KB |
Output is correct |
38 |
Correct |
5935 ms |
21836 KB |
Output is correct |
39 |
Correct |
6166 ms |
66296 KB |
Output is correct |
40 |
Correct |
7217 ms |
149504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
114 ms |
16224 KB |
Output is correct |
2 |
Correct |
117 ms |
18248 KB |
Output is correct |
3 |
Correct |
125 ms |
18524 KB |
Output is correct |
4 |
Correct |
119 ms |
18244 KB |
Output is correct |
5 |
Correct |
117 ms |
18248 KB |
Output is correct |
6 |
Correct |
114 ms |
18244 KB |
Output is correct |
7 |
Correct |
126 ms |
18412 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
115 ms |
18428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
114 ms |
16224 KB |
Output is correct |
2 |
Correct |
117 ms |
18248 KB |
Output is correct |
3 |
Correct |
125 ms |
18524 KB |
Output is correct |
4 |
Correct |
119 ms |
18244 KB |
Output is correct |
5 |
Correct |
117 ms |
18248 KB |
Output is correct |
6 |
Correct |
114 ms |
18244 KB |
Output is correct |
7 |
Correct |
126 ms |
18412 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
115 ms |
18428 KB |
Output is correct |
12 |
Correct |
883 ms |
28452 KB |
Output is correct |
13 |
Correct |
910 ms |
28228 KB |
Output is correct |
14 |
Correct |
886 ms |
28396 KB |
Output is correct |
15 |
Correct |
899 ms |
28476 KB |
Output is correct |
16 |
Correct |
703 ms |
7508 KB |
Output is correct |
17 |
Correct |
698 ms |
7428 KB |
Output is correct |
18 |
Correct |
740 ms |
10852 KB |
Output is correct |
19 |
Correct |
894 ms |
28632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
7969 ms |
18692 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
7969 ms |
18692 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1486 ms |
2796 KB |
Output is correct |
2 |
Correct |
1581 ms |
2644 KB |
Output is correct |
3 |
Correct |
1701 ms |
2900 KB |
Output is correct |
4 |
Correct |
1745 ms |
2968 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1803 ms |
3044 KB |
Output is correct |
9 |
Correct |
1791 ms |
3016 KB |
Output is correct |
10 |
Correct |
1766 ms |
2984 KB |
Output is correct |
11 |
Correct |
1730 ms |
2840 KB |
Output is correct |
12 |
Correct |
1808 ms |
2736 KB |
Output is correct |
13 |
Correct |
1810 ms |
3232 KB |
Output is correct |
14 |
Correct |
1803 ms |
2724 KB |
Output is correct |
15 |
Correct |
1743 ms |
3156 KB |
Output is correct |
16 |
Correct |
1435 ms |
2600 KB |
Output is correct |
17 |
Correct |
1453 ms |
2640 KB |
Output is correct |
18 |
Correct |
1462 ms |
3380 KB |
Output is correct |
19 |
Correct |
1421 ms |
2496 KB |
Output is correct |
20 |
Correct |
1442 ms |
2492 KB |
Output is correct |
21 |
Correct |
1429 ms |
2576 KB |
Output is correct |
22 |
Correct |
1442 ms |
2692 KB |
Output is correct |
23 |
Correct |
1440 ms |
2836 KB |
Output is correct |
24 |
Correct |
1436 ms |
2644 KB |
Output is correct |
25 |
Correct |
1444 ms |
2836 KB |
Output is correct |
26 |
Correct |
1448 ms |
2860 KB |
Output is correct |
27 |
Correct |
1471 ms |
3100 KB |
Output is correct |
28 |
Correct |
1448 ms |
2584 KB |
Output is correct |
29 |
Correct |
1497 ms |
2596 KB |
Output is correct |
30 |
Correct |
2490 ms |
3372 KB |
Output is correct |
31 |
Correct |
3912 ms |
4432 KB |
Output is correct |
32 |
Correct |
6949 ms |
132292 KB |
Output is correct |
33 |
Correct |
2 ms |
348 KB |
Output is correct |
34 |
Correct |
2 ms |
348 KB |
Output is correct |
35 |
Correct |
2 ms |
348 KB |
Output is correct |
36 |
Correct |
1440 ms |
2680 KB |
Output is correct |
37 |
Correct |
1449 ms |
2484 KB |
Output is correct |
38 |
Correct |
5935 ms |
21836 KB |
Output is correct |
39 |
Correct |
6166 ms |
66296 KB |
Output is correct |
40 |
Correct |
7217 ms |
149504 KB |
Output is correct |
41 |
Correct |
114 ms |
16224 KB |
Output is correct |
42 |
Correct |
117 ms |
18248 KB |
Output is correct |
43 |
Correct |
125 ms |
18524 KB |
Output is correct |
44 |
Correct |
119 ms |
18244 KB |
Output is correct |
45 |
Correct |
117 ms |
18248 KB |
Output is correct |
46 |
Correct |
114 ms |
18244 KB |
Output is correct |
47 |
Correct |
126 ms |
18412 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
1 ms |
604 KB |
Output is correct |
51 |
Correct |
115 ms |
18428 KB |
Output is correct |
52 |
Correct |
883 ms |
28452 KB |
Output is correct |
53 |
Correct |
910 ms |
28228 KB |
Output is correct |
54 |
Correct |
886 ms |
28396 KB |
Output is correct |
55 |
Correct |
899 ms |
28476 KB |
Output is correct |
56 |
Correct |
703 ms |
7508 KB |
Output is correct |
57 |
Correct |
698 ms |
7428 KB |
Output is correct |
58 |
Correct |
740 ms |
10852 KB |
Output is correct |
59 |
Correct |
894 ms |
28632 KB |
Output is correct |
60 |
Runtime error |
7969 ms |
18692 KB |
Execution killed with signal 11 |
61 |
Halted |
0 ms |
0 KB |
- |