Submission #579878

#TimeUsernameProblemLanguageResultExecution timeMemory
579878cheetoseHorses (IOI15_horses)C++17
100 / 100
599 ms53424 KiB
#include <bits/stdc++.h> #define mp make_pair #define pb push_back #define X first #define Y second #define y0 y12 #define y1 y22 #define INF 987654321 #define PI 3.141592653589793238462643383279502884 #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c)) #define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c)) #define MEM0(a) memset((a),0,sizeof(a)) #define MEM_1(a) memset((a),-1,sizeof(a)) #define ALL(a) a.begin(),a.end() #define COMPRESS(a) sort(ALL(a));a.resize(unique(ALL(a))-a.begin()) #define SYNC ios_base::sync_with_stdio(false);cin.tie(0) using namespace std; typedef long long ll; typedef long double ld; typedef double db; typedef unsigned int uint; typedef unsigned long long ull; typedef pair<int, int> Pi; typedef pair<ll, ll> Pll; typedef pair<ld, ld> Pd; typedef vector<int> Vi; typedef vector<ll> Vll; typedef vector<ld> Vd; typedef vector<Pi> VPi; typedef vector<Pll> VPll; typedef vector<Pd> VPd; typedef tuple<int, int, int> iii; typedef tuple<int, int, int, int> iiii; typedef tuple<ll, ll, ll> LLL; typedef vector<iii> Viii; typedef vector<LLL> VLLL; typedef complex<double> base; const int MOD = 1000000007; ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; } int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 }; int ddx[] = { -1,-2,1,-2,2,-1,2,1 }, ddy[] = { -2,-1,-2,1,-1,2,1,2 }; int n; int a[500005],b[500005]; int treex[1050000],treey[1050000]; void Init(int node,int S,int E){ if(S==E){ treex[node]=a[S],treey[node]=b[S]; return; } int L=node<<1,R=L|1,M=S+E>>1; Init(L,S,M);Init(R,M+1,E); treex[node]=1ll*treex[L]*treex[R]%MOD; treey[node]=max(treey[L],treey[R]); } void upd(int node,int S,int E,int i){ if(S==E){ treex[node]=a[S],treey[node]=b[S]; return; } int L=node<<1,R=L|1,M=S+E>>1; if(i<=M)upd(L,S,M,i); else upd(R,M+1,E,i); treex[node]=1ll*treex[L]*treex[R]%MOD; treey[node]=max(treey[L],treey[R]); } int find(int node,int S,int E,int i,int j){ if(i>E || j<S)return 0; if(i<=S && j>=E)return treey[node]; int L=node<<1,R=L|1,M=S+E>>1; return max(find(L,S,M,i,j),find(R,M+1,E,i,j)); } int find2(int node,int S,int E,int i,int j){ if(i>E || j<S)return 1; if(i<=S && j>=E)return treex[node]; int L=node<<1,R=L|1,M=S+E>>1; return 1ll*find2(L,S,M,i,j)*find2(R,M+1,E,i,j)%MOD; } set<int> S; int Q(){ if(S.empty()){ return treey[1]; } auto it=S.end(); ll tmp=1,ttmp=1; it--; Vi v; while(tmp<=(ll)1e9){ v.pb(*it); tmp*=a[*it]; if(it==S.begin())break; it--; } reverse(ALL(v)); __int128 mx=0; fup(i,0,(int)v.size()-1,1){ ttmp*=a[v[i]]; mx=max(mx,(__int128)ttmp*b[v[i]]); if(i!=(int)v.size()-1){ mx=max(mx,(__int128)find(1,0,n-1,v[i]+1,v[i+1]-1)*ttmp); }else{ mx=max(mx,(__int128)find(1,0,n-1,v[i]+1,n-1)*ttmp); } } if(tmp<=(ll)1e9){ mx=max(mx,(__int128)find(1,0,n-1,0,v[0]-1)); mx%=MOD; }else{ mx=mx%MOD*find2(1,0,n-1,0,v[0]-1)%MOD; } return (int)mx; } int updateX(int i,int x){ if(a[i]>1)S.erase(i); a[i]=x; if(a[i]>1)S.insert(i); upd(1,0,n-1,i); return Q(); } int updateY(int i,int x){ b[i]=x; upd(1,0,n-1,i); return Q(); } int init(int N,int x[],int y[]){ n=N; fup(i,0,n-1,1){ a[i]=x[i],b[i]=y[i]; if(a[i]>1)S.insert(i); } Init(1,0,n-1); return Q(); }

Compilation message (stderr)

horses.cpp: In function 'void Init(int, int, int)':
horses.cpp:51:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   51 |  int L=node<<1,R=L|1,M=S+E>>1;
      |                        ~^~
horses.cpp:53:35: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   53 |  treex[node]=1ll*treex[L]*treex[R]%MOD;
      |              ~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'void upd(int, int, int, int)':
horses.cpp:61:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   61 |  int L=node<<1,R=L|1,M=S+E>>1;
      |                        ~^~
horses.cpp:64:35: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   64 |  treex[node]=1ll*treex[L]*treex[R]%MOD;
      |              ~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int find(int, int, int, int, int)':
horses.cpp:70:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   70 |  int L=node<<1,R=L|1,M=S+E>>1;
      |                        ~^~
horses.cpp: In function 'int find2(int, int, int, int, int)':
horses.cpp:76:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   76 |  int L=node<<1,R=L|1,M=S+E>>1;
      |                        ~^~
horses.cpp:77:48: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   77 |  return 1ll*find2(L,S,M,i,j)*find2(R,M+1,E,i,j)%MOD;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int Q()':
horses.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
horses.cpp:96:2: note: in expansion of macro 'fup'
   96 |  fup(i,0,(int)v.size()-1,1){
      |  ^~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
horses.cpp:127:2: note: in expansion of macro 'fup'
  127 |  fup(i,0,n-1,1){
      |  ^~~
#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...