# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1045598 |
2024-08-06T06:10:44 Z |
15분 56초! 15분 57초!(#11072) |
Cell Automaton (JOI23_cell) |
C++17 |
|
112 ms |
19184 KB |
#include <bits/stdc++.h>
using namespace std;
int n,q;
typedef pair<int,int> P;
typedef pair<int,P> iP;
P arr[100000];
int save[155];
vector<iP> vec;
vector<long long> odd;
vector<long long> even;
int main() {
scanf("%d %d",&n,&q);
for(int i=0;i<n;i++) {
int x,y;
scanf("%d %d",&x,&y);
arr[i]=P(x,y);
}
sort(arr,arr+n);
vec.push_back(iP(0,P(4*n,n)));
vec.push_back(iP(1,P(0,-n)));
for(int i=0;i<n;i++) {
if (i!=n-1) {
int d=arr[i+1].first-arr[i].first-1;
vec.push_back(iP(d+1,P(-2,d+1)));
if ((d+1)&1) {
odd.push_back(d+1);
}
else {
even.push_back(d+1);
}
}
if (i!=0) {
int d=arr[i].first-arr[i-1].first;
vec.push_back(iP(d+1,P(-2,d+1)));
if ((d+1)&1) {
odd.push_back(d+1);
}
else {
even.push_back(d+1);
}
}
}
sort(vec.begin(),vec.end());
sort(odd.begin(),odd.end());
sort(even.begin(),even.end());
long long a=0;
long long b=0;
int ind=0;
for(int i=0;i<q;i++) {
int t;
scanf("%d",&t);
while (ind<vec.size()&&vec[ind].first<=t) {
//printf("%d %d\n",vec[ind].second.first,vec[ind].second.second);
a+=vec[ind].second.first;
b+=vec[ind].second.second;
ind++;
}
long long ret=a*t+b;
if (t&1) {
ret-=upper_bound(odd.begin(),odd.end(),t)-odd.begin();
}
else if (t!=0) {
ret-=upper_bound(even.begin(),even.end(),t)-even.begin();
}
printf("%lld\n",ret);
}
return 0;
}
Compilation message
cell.cpp: In function 'int main()':
cell.cpp:54:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | while (ind<vec.size()&&vec[ind].first<=t) {
| ~~~^~~~~~~~~~~
cell.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | scanf("%d %d",&n,&q);
| ~~~~~^~~~~~~~~~~~~~~
cell.cpp:17:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
17 | scanf("%d %d",&x,&y);
| ~~~~~^~~~~~~~~~~~~~~
cell.cpp:53:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
53 | scanf("%d",&t);
| ~~~~~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
8452 KB |
Output is correct |
2 |
Correct |
42 ms |
8456 KB |
Output is correct |
3 |
Correct |
44 ms |
8716 KB |
Output is correct |
4 |
Correct |
52 ms |
8964 KB |
Output is correct |
5 |
Correct |
43 ms |
9232 KB |
Output is correct |
6 |
Correct |
43 ms |
9476 KB |
Output is correct |
7 |
Correct |
43 ms |
8696 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
42 ms |
8024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
8452 KB |
Output is correct |
2 |
Correct |
42 ms |
8456 KB |
Output is correct |
3 |
Correct |
44 ms |
8716 KB |
Output is correct |
4 |
Correct |
52 ms |
8964 KB |
Output is correct |
5 |
Correct |
43 ms |
9232 KB |
Output is correct |
6 |
Correct |
43 ms |
9476 KB |
Output is correct |
7 |
Correct |
43 ms |
8696 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
42 ms |
8024 KB |
Output is correct |
12 |
Correct |
110 ms |
18168 KB |
Output is correct |
13 |
Correct |
108 ms |
18176 KB |
Output is correct |
14 |
Correct |
112 ms |
19184 KB |
Output is correct |
15 |
Correct |
110 ms |
18936 KB |
Output is correct |
16 |
Correct |
60 ms |
7276 KB |
Output is correct |
17 |
Correct |
54 ms |
7360 KB |
Output is correct |
18 |
Correct |
82 ms |
10788 KB |
Output is correct |
19 |
Correct |
107 ms |
18424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |