Submission #461157

#TimeUsernameProblemLanguageResultExecution timeMemory
461157zaneyuHorses (IOI15_horses)C++14
17 / 100
1000 ms19536 KiB
/*input 3 2 1 3 3 4 1 1 2 1 2 */ #include "horses.h" #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; #pragma GCC optimize("unroll-loops,no-stack-protector") //order_of_key #of elements less than x // find_by_order kth element using ll = long long; using ld = long double; using pii = pair<ll,ll>; #define f first #define s second #define pb push_back #define REP(i,n) for(int i=0;i<n;i++) #define REP1(i,n) for(int i=1;i<=n;i++) #define FILL(n,x) memset(n,x,sizeof(n)) #define ALL(_a) _a.begin(),_a.end() #define sz(x) (int)x.size() #define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end())))) const ll INF64=4e18; const ll INF=0x3f3f3f3f; const ll MOD=1e9+7; const ld PI=acos(-1); const ld eps=1e-6; #define lowb(x) x&(-x) #define MNTO(x,y) x=min(x,(__typeof__(x))y) #define MXTO(x,y) x=max(x,(__typeof__(x))y) ll sub(ll a,ll b){ ll x=a-b; while(x<0) x+=MOD; while(x>MOD) x-=MOD; return x; } ll mult(ll a,ll b){ return (a*b)%MOD; } ll mypow(ll a,ll b){ if(b<=0) return 1; ll res=1LL; while(b){ if(b&1) res=(res*a)%MOD; a=(a*a)%MOD; b>>=1; } return res; } const int maxn=5e5+5; const ll maxlg=__lg(maxn)+2; int val[4*maxn],md[4*maxn]; inline void mdf(int idx,int l,int r,int p,int x){ if(l>p or r<p) return; if(l==r){ val[idx]=md[idx]=x; return; } int mid=(l+r)/2; mdf(idx*2,l,mid,p,x); mdf(idx*2+1,mid+1,r,p,x); val[idx]=min((ll)INF,(ll)val[idx*2]*val[idx*2+1]); md[idx]=mult(md[idx*2],md[idx*2+1]); } inline int qv(int idx,int l,int r,int ql,int qr){ if(l>qr or r<ql) return 1; if(ql<=l and r<=qr) return val[idx]; int mid=(l+r)/2; return min((ll)INF,(ll)qv(idx*2,l,mid,ql,qr)*qv(idx*2+1,mid+1,r,ql,qr)); } inline int qm(int idx,int l,int r,int ql,int qr){ if(l>qr or r<ql) return 1; if(ql<=l and r<=qr) return md[idx]; int mid=(l+r)/2; return mult(qm(idx*2,l,mid,ql,qr),qm(idx*2+1,mid+1,r,ql,qr)); } int opt[4*maxn]; int y[maxn],n; void build(int idx,int l,int r){ if(l==r){ opt[idx]=l; return; } int mid=(l+r)/2; build(idx*2,l,mid); build(idx*2+1,mid+1,r); } void upd(int idx,int l,int r,int p){ if(r<p or l>p) return; if(l==r){ return; } int mid=(l+r)/2; upd(idx*2,l,mid,p); upd(idx*2+1,mid+1,r,p); if(y[opt[idx*2+1]]*qv(1,0,n-1,opt[idx*2]+1,opt[idx*2+1])>=y[opt[idx*2]]) opt[idx]=opt[idx*2+1]; else opt[idx]=opt[idx*2]; } int init(int N, int X[], int Y[]) { n=N; REP(i,n) mdf(1,0,n-1,i,X[i]); build(1,0,n-1); REP(i,n) y[i]=Y[i],upd(1,0,n-1,i); return mult(y[opt[1]],qm(1,0,n-1,0,opt[1])); } int updateX(int pos, int val) { mdf(1,0,n-1,pos,val); upd(1,0,n-1,pos); return mult(y[opt[1]],qm(1,0,n-1,0,opt[1])); } int updateY(int pos, int val) { y[pos]=val; upd(1,0,n-1,pos); return mult(y[opt[1]],qm(1,0,n-1,0,opt[1])); }

Compilation message (stderr)

horses.cpp: In function 'void mdf(int, int, int, int, int)':
horses.cpp:69:17: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   69 |     val[idx]=min((ll)INF,(ll)val[idx*2]*val[idx*2+1]);
      |              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
horses.cpp:70:17: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   70 |     md[idx]=mult(md[idx*2],md[idx*2+1]);
      |             ~~~~^~~~~~~~~~~~~~~~~~~~~~~
horses.cpp: In function 'int qv(int, int, int, int, int)':
horses.cpp:76:15: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   76 |     return min((ll)INF,(ll)qv(idx*2,l,mid,ql,qr)*qv(idx*2+1,mid+1,r,ql,qr));
      |            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
horses.cpp: In function 'int qm(int, int, int, int, int)':
horses.cpp:82:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   82 |     return mult(qm(idx*2,l,mid,ql,qr),qm(idx*2+1,mid+1,r,ql,qr));
      |            ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:111:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  111 |     return mult(y[opt[1]],qm(1,0,n-1,0,opt[1]));
      |            ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:114:26: warning: declaration of 'val' shadows a global declaration [-Wshadow]
  114 | int updateX(int pos, int val) {
      |                      ~~~~^~~
horses.cpp:59:5: note: shadowed declaration is here
   59 | int val[4*maxn],md[4*maxn];
      |     ^~~
horses.cpp:117:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  117 |     return mult(y[opt[1]],qm(1,0,n-1,0,opt[1]));
      |            ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:120:26: warning: declaration of 'val' shadows a global declaration [-Wshadow]
  120 | int updateY(int pos, int val) {
      |                      ~~~~^~~
horses.cpp:59:5: note: shadowed declaration is here
   59 | int val[4*maxn],md[4*maxn];
      |     ^~~
horses.cpp:123:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  123 |     return mult(y[opt[1]],qm(1,0,n-1,0,opt[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...