# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1099955 |
2024-10-12T08:06:04 Z |
ttamx |
Mosaic (IOI24_mosaic) |
C++17 |
|
278 ms |
23492 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<ll> mosaic(vector<int> X,vector<int> Y,vector<int> T,vector<int> B,vector<int> L,vector<int> R){
int n=X.size();
int q=T.size();
if(n<3){
X.resize(3);
Y.resize(3);
n=3;
}
vector<ll> ans(q);
vector<int> a(n),b(n),c(n),d(n);
a[0]=Y[1];
b[0]=X[1];
for(int i=1;i<n;i++){
if(a[i-1]+X[i]==0){
a[i]=1;
}
}
for(int i=1;i<n;i++){
if(b[i-1]+Y[i]==0){
b[i]=1;
}
}
c[1]=b[2];
d[1]=a[2];
vector<ll> s;
for(int i=2;i<n;i++){
if(c[i-1]+a[i]==0){
c[i]=1;
s.emplace_back(2-i);
}
}
for(int i=2;i<n;i++){
if(d[i-1]+b[i]==0){
d[i]=1;
if(i>2){
s.emplace_back(i-2);
}
}
}
sort(s.begin(),s.end());
auto qs=s;
for(int i=1;i<qs.size();i++){
qs[i]+=qs[i-1];
}
for(int i=1;i<n;i++){
X[i]+=X[i-1];
Y[i]+=Y[i-1];
a[i]+=a[i-1];
b[i]+=b[i-1];
}
for(int i=0;i<q;i++){
if(T[i]==0){
ans[i]+=X[R[i]]-(L[i]>0?X[L[i]-1]:0);
T[i]++;
}
}
for(int i=0;i<q;i++){
if(T[i]<=B[i]&&L[i]==0){
ans[i]+=Y[B[i]]-Y[T[i]-1];
L[i]++;
}
}
for(int i=0;i<q;i++){
if(T[i]<=B[i]&&L[i]<=R[i]&&T[i]==1){
ans[i]+=a[R[i]]-a[L[i]-1];
T[i]++;
}
}
for(int i=0;i<q;i++){
if(T[i]<=B[i]&&L[i]<=R[i]&&L[i]==1){
ans[i]+=b[B[i]]-b[T[i]-1];
L[i]++;
}
}
for(int i=0;i<q;i++){
if(T[i]>B[i]||L[i]>R[i]){
continue;
}
{
auto itl=lower_bound(s.begin(),s.end(),T[i]-R[i]);
auto itr=upper_bound(s.begin(),s.end(),T[i]-L[i]);
if(itl!=itr){
auto it=lower_bound(itl,itr,B[i]-R[i]);
int l=itl-s.begin();
int r=itr-s.begin();
int p=it-s.begin();
ans[i]+=((p>0?qs[p-1]:0LL)-(l>0?qs[l-1]:0LL))+1LL*(R[i]-T[i])*(p-l);
ans[i]+=1LL*(B[i]-T[i])*(r-p);
ans[i]+=r-l;
}
}
if(T[i]!=B[i]){
auto itl=lower_bound(s.begin(),s.end(),T[i]-L[i]+1);
auto itr=upper_bound(s.begin(),s.end(),B[i]-L[i]);
if(itl!=itr){
auto it=lower_bound(itl,itr,B[i]-R[i]);
int l=itl-s.begin();
int r=itr-s.begin();
int p=it-s.begin();
ans[i]+=-((r>0?qs[r-1]:0LL)-(p>0?qs[p-1]:0LL))+1LL*(B[i]-L[i])*(r-p);
ans[i]+=1LL*(R[i]-L[i])*(p-l);
ans[i]+=r-l;
}
}
}
return ans;
}
Compilation message
mosaic.cpp: In function 'std::vector<long long int> mosaic(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
mosaic.cpp:48:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for(int i=1;i<qs.size();i++){
| ~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 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 |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 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 |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
111 ms |
21444 KB |
Output is correct |
2 |
Correct |
109 ms |
21148 KB |
Output is correct |
3 |
Correct |
95 ms |
20724 KB |
Output is correct |
4 |
Correct |
99 ms |
21188 KB |
Output is correct |
5 |
Correct |
77 ms |
16324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 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 |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
117 ms |
12112 KB |
Output is correct |
19 |
Correct |
110 ms |
11860 KB |
Output is correct |
20 |
Correct |
129 ms |
11776 KB |
Output is correct |
21 |
Correct |
111 ms |
11648 KB |
Output is correct |
22 |
Correct |
119 ms |
11600 KB |
Output is correct |
23 |
Correct |
128 ms |
11604 KB |
Output is correct |
24 |
Correct |
84 ms |
11896 KB |
Output is correct |
25 |
Correct |
106 ms |
11900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
79 ms |
9576 KB |
Output is correct |
2 |
Correct |
264 ms |
23400 KB |
Output is correct |
3 |
Correct |
278 ms |
22728 KB |
Output is correct |
4 |
Correct |
224 ms |
22976 KB |
Output is correct |
5 |
Correct |
221 ms |
23096 KB |
Output is correct |
6 |
Correct |
155 ms |
23488 KB |
Output is correct |
7 |
Correct |
181 ms |
23492 KB |
Output is correct |
8 |
Correct |
131 ms |
23488 KB |
Output is correct |
9 |
Correct |
227 ms |
17860 KB |
Output is correct |
10 |
Correct |
152 ms |
17860 KB |
Output is correct |
11 |
Correct |
164 ms |
17864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
168 ms |
23232 KB |
Output is correct |
2 |
Correct |
152 ms |
23232 KB |
Output is correct |
3 |
Correct |
133 ms |
21700 KB |
Output is correct |
4 |
Correct |
140 ms |
21744 KB |
Output is correct |
5 |
Correct |
120 ms |
23492 KB |
Output is correct |
6 |
Correct |
123 ms |
17816 KB |
Output is correct |
7 |
Correct |
109 ms |
15760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
111 ms |
21444 KB |
Output is correct |
2 |
Correct |
109 ms |
21148 KB |
Output is correct |
3 |
Correct |
95 ms |
20724 KB |
Output is correct |
4 |
Correct |
99 ms |
21188 KB |
Output is correct |
5 |
Correct |
77 ms |
16324 KB |
Output is correct |
6 |
Correct |
168 ms |
23232 KB |
Output is correct |
7 |
Correct |
152 ms |
23232 KB |
Output is correct |
8 |
Correct |
133 ms |
21700 KB |
Output is correct |
9 |
Correct |
140 ms |
21744 KB |
Output is correct |
10 |
Correct |
120 ms |
23492 KB |
Output is correct |
11 |
Correct |
123 ms |
17816 KB |
Output is correct |
12 |
Correct |
109 ms |
15760 KB |
Output is correct |
13 |
Correct |
164 ms |
23240 KB |
Output is correct |
14 |
Correct |
141 ms |
23256 KB |
Output is correct |
15 |
Correct |
164 ms |
23232 KB |
Output is correct |
16 |
Correct |
135 ms |
21696 KB |
Output is correct |
17 |
Correct |
147 ms |
22568 KB |
Output is correct |
18 |
Correct |
157 ms |
23224 KB |
Output is correct |
19 |
Correct |
122 ms |
16564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
111 ms |
21444 KB |
Output is correct |
20 |
Correct |
109 ms |
21148 KB |
Output is correct |
21 |
Correct |
95 ms |
20724 KB |
Output is correct |
22 |
Correct |
99 ms |
21188 KB |
Output is correct |
23 |
Correct |
77 ms |
16324 KB |
Output is correct |
24 |
Correct |
117 ms |
12112 KB |
Output is correct |
25 |
Correct |
110 ms |
11860 KB |
Output is correct |
26 |
Correct |
129 ms |
11776 KB |
Output is correct |
27 |
Correct |
111 ms |
11648 KB |
Output is correct |
28 |
Correct |
119 ms |
11600 KB |
Output is correct |
29 |
Correct |
128 ms |
11604 KB |
Output is correct |
30 |
Correct |
84 ms |
11896 KB |
Output is correct |
31 |
Correct |
106 ms |
11900 KB |
Output is correct |
32 |
Correct |
79 ms |
9576 KB |
Output is correct |
33 |
Correct |
264 ms |
23400 KB |
Output is correct |
34 |
Correct |
278 ms |
22728 KB |
Output is correct |
35 |
Correct |
224 ms |
22976 KB |
Output is correct |
36 |
Correct |
221 ms |
23096 KB |
Output is correct |
37 |
Correct |
155 ms |
23488 KB |
Output is correct |
38 |
Correct |
181 ms |
23492 KB |
Output is correct |
39 |
Correct |
131 ms |
23488 KB |
Output is correct |
40 |
Correct |
227 ms |
17860 KB |
Output is correct |
41 |
Correct |
152 ms |
17860 KB |
Output is correct |
42 |
Correct |
164 ms |
17864 KB |
Output is correct |
43 |
Correct |
168 ms |
23232 KB |
Output is correct |
44 |
Correct |
152 ms |
23232 KB |
Output is correct |
45 |
Correct |
133 ms |
21700 KB |
Output is correct |
46 |
Correct |
140 ms |
21744 KB |
Output is correct |
47 |
Correct |
120 ms |
23492 KB |
Output is correct |
48 |
Correct |
123 ms |
17816 KB |
Output is correct |
49 |
Correct |
109 ms |
15760 KB |
Output is correct |
50 |
Correct |
164 ms |
23240 KB |
Output is correct |
51 |
Correct |
141 ms |
23256 KB |
Output is correct |
52 |
Correct |
164 ms |
23232 KB |
Output is correct |
53 |
Correct |
135 ms |
21696 KB |
Output is correct |
54 |
Correct |
147 ms |
22568 KB |
Output is correct |
55 |
Correct |
157 ms |
23224 KB |
Output is correct |
56 |
Correct |
122 ms |
16564 KB |
Output is correct |
57 |
Correct |
248 ms |
23232 KB |
Output is correct |
58 |
Correct |
203 ms |
22836 KB |
Output is correct |
59 |
Correct |
236 ms |
23236 KB |
Output is correct |
60 |
Correct |
225 ms |
22468 KB |
Output is correct |
61 |
Correct |
227 ms |
22440 KB |
Output is correct |
62 |
Correct |
202 ms |
22772 KB |
Output is correct |
63 |
Correct |
208 ms |
17700 KB |
Output is correct |
64 |
Correct |
170 ms |
15308 KB |
Output is correct |