Submission #82290

#TimeUsernameProblemLanguageResultExecution timeMemory
82290farukkastamonudaHorses (IOI15_horses)C++14
17 / 100
189 ms21500 KiB
#include "horses.h" #include <bits/stdc++.h> #define fi first #define se second #define lo long long #define inf 10000000000000009 #define md 1000000007 #define li 500005 #define mp make_pair //#define lo int long long #define pb push_back #define mid (start+end)/2 using namespace std; lo int n,A1[li],B1[li],A[li],B[li]; lo int tree[li*4],lazy[li*4]; lo pw(lo a,lo b){ if(b==0) return 1; if(b==1) return a%md; lo t=pw(a,b/2); t=(t%md*t%md)%md; if(b%2==1) t=(t%md*a%md)%md; return t%md; } void build(int node,int start,int end){ if(start==end){ tree[node]=(A[start]%md*B[start]%md)%md; return ; } build(node*2,start,mid);build(node*2+1,mid+1,end); tree[node]=max((lo)tree[node*2]%md,(lo)tree[node*2+1]%md); } void push(int node,int start,int end){ if(lazy[node]==0) return ; if(tree[node]==0) tree[node]=1; tree[node]=(lo)((lo)tree[node]%md*pw(lazy[node],end-start+1)%md)%md; if(start!=end){ if(lazy[node*2]==0) lazy[node*2]=(lo)lazy[node]%md; else lazy[node*2]=(lo)((lo)lazy[node*2]%md*(lo)lazy[node]%md)%md; if(lazy[node*2+1]==0) lazy[node*2+1]=(lo)lazy[node]%md; else lazy[node*2+1]=(lo)((lo)lazy[node*2+1]%md*(lo)lazy[node]%md)%md; } lazy[node]=0; } lo query(int node,int start,int end,int l,int r){ if(start>end || start>r || end<l) return -((inf)%md); push(node,start,end); if(start>=l && end<=r) return (lo)tree[node]%md; lo q1=((lo)query(node*2,start,mid,l,r)%md+md)%md; lo q2=((lo)query(node*2+1,mid+1,end,l,r)%md+md)%md; return max(q1,q2); } int init(int N,int X[],int Y[]){ n=N; for(int i=0;i<n;i++) A[i+1]=X[i]; for(int i=0;i<n;i++) B[i+1]=Y[i]; for(int i=1;i<=n;i++){ A[i]=(A[i]%md*(i!=1?A[i-1]:1)%md)%md; } build(1,1,n); int bas=(lo)query(1,1,n,1,n)%md; return bas; } void update(int node,int start,int end,int l,int r,lo val){ push(node,start,end); if(start>end || start>r || end<l) return ; if(start>=l && end<=r){ if(lazy[node]==0) lazy[node]=val; else lazy[node]=(lo)((lo)lazy[node]%md*(lo)val%md)%md; push(node,start,end); return ; } update(node*2,start,mid,l,r,val);update(node*2+1,mid+1,end,l,r,val); tree[node]=max(tree[node*2],tree[node*2+1]); } int updateX(int pos,int val){ //A[pos+1]=val; pos++; lo ggwp=val,htht=A[pos]; A[pos]=val; update(1,1,n,pos,n,ggwp); update(1,1,n,pos,n,pw(htht,md-2)); int bas=(lo )query(1,1,n,1,n)%md; return bas; } int updateY(int pos,int val){ pos++; lo ggwp=val,htht=B[pos]; B[pos]=val; update(1,1,n,pos,pos,ggwp); update(1,1,n,pos,pos,pw(htht,md-2)); int bas=(lo)query(1,1,n,1,n)%md; return bas; } //~ int main(){ //~ scanf("%lld",&n); //~ for(int i=0;i<n;i++) scanf("%d",&A1[i]); //~ for(int i=0;i<n;i++) scanf("%d",&B1[i]); //~ int ty=init(n,A1,B1); //~ ty=updateY(1,2); //~ printf("%d\n",ty); //~ return 0; //~ }

Compilation message (stderr)

horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:59:13: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  build(1,1,n);
             ^
horses.cpp:60:29: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  int bas=(lo)query(1,1,n,1,n)%md;
                             ^
horses.cpp:60:29: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
horses.cpp:60:30: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  int bas=(lo)query(1,1,n,1,n)%md;
                              ^
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:80:25: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  update(1,1,n,pos,n,ggwp);
                         ^
horses.cpp:80:25: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
horses.cpp:81:34: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  update(1,1,n,pos,n,pw(htht,md-2));
                                  ^
horses.cpp:81:34: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
horses.cpp:82:30: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  int bas=(lo )query(1,1,n,1,n)%md;
                              ^
horses.cpp:82:30: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
horses.cpp:82:31: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  int bas=(lo )query(1,1,n,1,n)%md;
                               ^
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:89:27: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  update(1,1,n,pos,pos,ggwp);
                           ^
horses.cpp:90:36: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  update(1,1,n,pos,pos,pw(htht,md-2));
                                    ^
horses.cpp:91:29: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  int bas=(lo)query(1,1,n,1,n)%md;
                             ^
horses.cpp:91:29: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
horses.cpp:91:30: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  int bas=(lo)query(1,1,n,1,n)%md;
                              ^
#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...