# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1108635 |
2024-11-04T17:08:41 Z |
Ludissey |
Mosaic (IOI24_mosaic) |
C++17 |
|
134 ms |
43440 KB |
#include "mosaic.h"
#include <bits/stdc++.h>
#define int long long
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
int q,n;
vector<vector<int>> lft;
vector<vector<int>> top;
vector<int> dia;
vector<int> diapref;
vector<int> diaSpref;
vector<int> diaSprefINV;
// X cest le top
// Y cest la gauche
// [le x][le y]
int todia(int x, int y){
return (n-x-1)+y;
}
int prefL(int l, int r, int t ,int b){
if(l>r||t>b) return 0;
int sm=lft[r][b];
if(l>0) sm-=lft[l-1][b];
if(t>0) sm-=lft[r][t-1];
if(l>0&&t>0) sm+=lft[l-1][t-1];
return sm;
}
int prefT(int l, int r, int t ,int b){
if(l>r||t>b) return 0;
int sm=top[r][b];
if(l>0) sm-=top[l-1][b];
if(t>0) sm-=top[r][t-1];
if(l>0&&t>0) sm+=top[l-1][t-1];
return sm;
}
int SprefINV(int l, int r){
int sm=diaSpref[l];
if(r<n-1) sm-=diaSpref[r+1];
int p=diapref[r];
if(l>0) p-=diapref[l-1];
sm-=p*(sz(dia)-(r+1));
return sm;
}
int Spref(int l, int r){
int sm=diaSpref[r];
if(l>0) sm-=diaSpref[l-1];
int p=diapref[r];
if(l>0) p-=diapref[l-1];
sm-=p*l;
return sm;
}
std::vector<long long> mosaic(std::vector<signed> X, std::vector<signed> Y, std::vector<signed> T, std::vector<signed> B,std::vector<signed> L, std::vector<signed> R) {
q = sz(T); n=sz(Y);
lft.resize(3,vector<int>(n,0));
top.resize(n,vector<int>(3,0));
dia.resize(n+n-1,0);
diaSprefINV.resize(n+n+4,0);
diaSpref.resize(n+n+4,0);
diapref.resize(n+n+4,0);
for (int i = 0; i < n; i++)
{
lft[0][i]=Y[i];
top[i][0]=X[i];
}
if(n>1){
lft[1][0]=X[1];
top[0][1]=Y[1];
if(n>2){
lft[2][0]=X[2];
top[0][2]=Y[2];
}
}
for (int i = 1; i < n&&n>1; i++)
{
top[i][1]=(top[i-1][1]==0&&top[i][0]==0);
lft[1][i]=(lft[1][i-1]==0&&lft[0][i]==0);
}
for (int i = 1; i < n&&n>2; i++)
{
top[i][2]=(top[i-1][2]==0&&top[i][1]==0);
lft[2][i]=(lft[2][i-1]==0&&lft[1][i]==0);
dia[todia(i,2)]=top[i][2];
dia[todia(2,i)]=lft[2][i];
}
for (int i = 0; i < n; i++){
for (int j = 0; j < min(n,3LL); j++)
{
if(j>0) top[i][j]+=top[i][j-1];
if(i>0) top[i][j]+=top[i-1][j];
if(i>0&&j>0) top[i][j]-=top[i-1][j-1];
if(j>0) lft[j][i]+=lft[j-1][i];
if(i>0) lft[j][i]+=lft[j][i-1];
if(i>0&&j>0) lft[j][i]-=lft[j-1][i-1];
}
}
for (int i = 0; i < sz(dia); i++)
{
diapref[i]=dia[i];
diaSpref[i]=dia[i]*(i+1);
if(i>0) diapref[i]+=diapref[i-1];
if(i>0) diaSpref[i]+=diaSpref[i-1];
// --
int j=(sz(dia)-(i+1));
diaSprefINV[j]=dia[j]*(sz(dia)-(j));
if(j<sz(dia)-1) diaSprefINV[j]+=diaSprefINV[j+1];
}
std::vector<long long> C(q, 0);
for (int i = 0; i < q; i++)
{
int _l=L[i],r=R[i],_t=T[i],b=B[i];
int l=max(3LL,_l);
int t=max(3LL,_t);
int sm=prefT(_l,r,_t,min(2LL,b));
sm+=prefL(_l,min(2LL,r),_t,b);
sm-=prefL(_l,min(2LL,r),_t,min(2LL,b));
if(l>r||t>b) { C[i]=sm; continue; }
int lng=min(r-l,b-t);
sm+=SprefINV(todia(l,b)-lng,todia(l,b));
sm+=Spref(todia(r,t),todia(r,t)+lng);
if((r-l)==(b-t)) sm-=dia[todia(l,t)]*lng;
else{
int dp=diapref[todia(l,b)-lng]-diapref[todia(r,t)+lng];
sm+=(dp)*lng;
}
C[i]=sm;
}
return C;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
504 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
0 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
504 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
0 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
548 KB |
Output is correct |
11 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
109 ms |
40680 KB |
Output is correct |
2 |
Correct |
110 ms |
43308 KB |
Output is correct |
3 |
Correct |
103 ms |
42796 KB |
Output is correct |
4 |
Correct |
134 ms |
43440 KB |
Output is correct |
5 |
Correct |
83 ms |
27192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
504 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
0 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
548 KB |
Output is correct |
11 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
56 ms |
9136 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
122 ms |
39468 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
109 ms |
40680 KB |
Output is correct |
2 |
Correct |
110 ms |
43308 KB |
Output is correct |
3 |
Correct |
103 ms |
42796 KB |
Output is correct |
4 |
Correct |
134 ms |
43440 KB |
Output is correct |
5 |
Correct |
83 ms |
27192 KB |
Output is correct |
6 |
Incorrect |
122 ms |
39468 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
504 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
0 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
548 KB |
Output is correct |
12 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |