Submission #310520

#TimeUsernameProblemLanguageResultExecution timeMemory
310520mosiashvililukaHorses (IOI15_horses)C++14
34 / 100
415 ms76664 KiB
#include "horses.h"
//
#include<bits/stdc++.h>
using namespace std;
const int N=2300009;
long long a,b,c,d,e,i,j,ii,jj,zx,xc,tp,tes,t,X[500009],Y[500009],seg[N],seg2[N],seg3[N],za,mod=1000000007LL,x,y,xx,yy;
bool bo2[N],bo3[N];
void up(int q){
	if(q==0) return;
	x=X[seg[q*2]];y=Y[seg[q*2]];
	xx=X[seg[q*2+1]];yy=Y[seg[q*2+1]];
	if(bo3[q*2]==1||bo2[q*2+1]==1){
		seg[q]=seg[q*2+1];
	}else{
		bool bo=0;
		zx=seg3[q*2]*seg2[q*2+1];
		if(zx>mod) bo=1;
		zx%=mod;
		zx*=xx;
		if(zx>mod) bo=1;
		zx%=mod;
		zx*=yy;
		if(zx>mod) bo=1;
		zx%=mod;
		if(bo3[q*2]==1||bo2[q*2+1]==1) bo=1;
		if(bo==1||zx>y){
			seg[q]=seg[q*2+1];
		}else{
			seg[q]=seg[q*2];
		}
	}
	if(seg[q]==seg[q*2]){
		seg2[q]=seg2[q*2];
		bo2[q]=bo2[q*2];
		bool bo=0;
		zx=seg3[q*2]*seg2[q*2+1];
		if(zx>mod) bo=1;
		zx%=mod;
		zx*=xx;
		if(zx>mod) bo=1;
		zx%=mod;
		zx*=seg3[q*2+1];
		if(zx>mod) bo=1;
		zx%=mod;
		if(bo3[q*2]==1||bo2[q*2+1]==1||bo3[q*2+1]==1) bo=1;
		bo3[q]=bo;
		seg3[q]=zx;
	}else{
		seg3[q]=seg3[q*2+1];
		bo3[q]=bo3[q*2+1];
		bool bo=0;
		zx=seg2[q*2+1]*seg3[q*2];
		if(zx>mod) bo=1;
		zx%=mod;
		zx*=x;
		if(zx>mod) bo=1;
		zx%=mod;
		zx*=seg2[q*2];
		if(zx>mod) bo=1;
		zx%=mod;
		if(bo2[q*2+1]==1||bo3[q*2]==1||bo2[q*2]==1) bo=1;
		bo2[q]=bo;
		seg2[q]=zx;
	}
	up(q/2);
}
void upd(int q){
	seg[q+za-1]=q;
	seg2[q+za-1]=seg3[q+za-1]=1LL;
	bo2[q+za-1]=bo3[q+za-1]=0;
	up((q+za-1)/2);
}
//
int init(int N, int XX[], int YY[]) {
	a=N;
	for(i=1; i<=a; i++){
		X[i]=XX[i-1];Y[i]=YY[i-1];
	}
	za=1;
	while(za<a) za*=2;
	for(i=1; i<=za; i++){
		upd(i);
	}
	zx=seg2[1]*X[seg[1]];zx%=mod;
	zx*=Y[seg[1]];zx%=mod;
	return zx;
}

int updateX(int pos, int val) {	
	c=pos;d=val;
	c++;
	X[c]=d;
	upd(c);
	zx=seg2[1]*X[seg[1]];zx%=mod;
	zx*=Y[seg[1]];zx%=mod;
	return zx;
}

int updateY(int pos, int val) {
	c=pos;d=val;
	c++;
	Y[c]=d;
	upd(c);
	zx=seg2[1]*X[seg[1]];zx%=mod;
	zx*=Y[seg[1]];zx%=mod;
	return zx;
}

Compilation message (stderr)

horses.cpp: In function 'void upd(int)':
horses.cpp:71:13: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   71 |  up((q+za-1)/2);
      |     ~~~~~~~~^~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:74:35: warning: declaration of 'N' shadows a global declaration [-Wshadow]
   74 | int init(int N, int XX[], int YY[]) {
      |                                   ^
horses.cpp:5:11: note: shadowed declaration is here
    5 | const int N=2300009;
      |           ^
horses.cpp:82:7: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   82 |   upd(i);
      |       ^
horses.cpp:86:9: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   86 |  return zx;
      |         ^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:93:6: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   93 |  upd(c);
      |      ^
horses.cpp:96:9: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   96 |  return zx;
      |         ^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:103:6: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  103 |  upd(c);
      |      ^
horses.cpp:106:9: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  106 |  return zx;
      |         ^~
#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...