Submission #1244473

#TimeUsernameProblemLanguageResultExecution timeMemory
1244473AlperenT_Mosaic (IOI24_mosaic)C++20
0 / 100
1104 ms255244 KiB
#include "mosaic.h"

#include <vector>
#include <bits/stdc++.h> 
#pragma GCC optimize("O3,unroll-loops") 
#pragma GCC target("avx2") 
#define pb push_back
#define F first
#define pii pair<int,int> 
#define all(a) a.begin(),a.end()
#define S second 
#define sz(a) (int)a.size()
#define rep(i , a , b) for(int i = (a) ; i <= (b) ; i++)
#define per(i , a , b) for(int i = (a) ; i >= (b) ; i--)
#define ld double
#define ll long long 
using namespace std ;
const int maxn = 1e6   + 100 , inf = 1e9 , mod = 998244353;
map <int , ll>   a[maxn] , s[maxn] ;
ll fen[maxn]  ,n  ,b[maxn];
int ch(int x, int y){
  if(x+y==0)return 1; 
  return 0 ;
}
void upd(int x, int w){
  while(x <= 2*n){
    fen[x] += w;
    x += x&-x ;
  }
}
ll que(int x){
  ll ans = 0;
  while(x){
    ans += fen[x] ;
    x -= x&-x ;
  }
  return ans; 
}
vector <int> vec[maxn] ; 
ll sm[maxn]; 
std::vector<long long> mosaic(std::vector<int> X, std::vector<int> Y,std::vector<int> T, std::vector<int> B,std::vector<int> L, std::vector<int> R) {
  n = sz(X) ;
  rep(i , 0 , n-1){
    a[0][i] = X[i] ;
    a[i][0] = Y[i] ;
  }
  rep(i , 1, n-1){
    rep(j ,1, n-1){
      if(i > 50 && j > 50)break ;
      if(a[i-1][j]==0 && a[i][j-1]==0){
        a[i][j] = 1; 
      }else{
        a[i][j] = 0 ;
      }
      s[i][j] = a[i][j] ;
      if(i)s[i][j] += s[i-1][j] ;
      if(j)s[i][j] += s[i][j-1];
      if(i&&j)s[i][j] -= s[i-1][j-1] ;
    }
  }
  vector <ll> C ;
  rep(i , 0 , sz(T)-1){
    if(T[i] <= 50){
      ll ans = s[B[i]][R[i]] ;
      if(L[i])ans -= s[B[i]][L[i]-1] ;
      if(T[i])ans -= s[T[i]-1][R[i]] ;
      if(L[i] && T[i])ans += s[T[i]-1][L[i]-1] ;
      sm[i] = ans; 
    }else{
      sm[i] =0 ; 
      while(L[i] <= 50 && L[i] <= R[i]){
        sm[i] += a[T[i]][L[i]] ;
        L[i]++ ;
      }
      if(L[i] > R[i])continue ;
      vec[T[i]].pb(i) ;
    }
  }
  rep(i , 50 , n){
    b[i+n] = a[50][i] ;
    upd(i+n , b[i]) ;
  }
  int l = 50+n , r= n+n ;
  rep(i , 51  ,n){
      b[l-1] = ch(a[i][49] , b[l]) ;
      l--;
      r-- ;
      upd(l , b[l]) ;
      for(int x : vec[i]){
        sm[x] += que(l+R[x]-50) -que(l+L[x]-50 - 1);  
      }
  }
  rep(i , 0 ,sz(T)-1){
    C.pb(sm[i]) ;
  }
  return C;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...