Submission #830588

# Submission time Handle Problem Language Result Execution time Memory
830588 2023-08-19T08:12:21 Z Supersonic Horses (IOI15_horses) C++14
100 / 100
490 ms 72592 KB
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
ll h[500001];
ll x[500001];
ll y[500001];
bool subtask3=1;
int n;
set<int, greater<int>> g1;
ll tree[1048577];
pair<ll,int> ytree[1048577];
void modify(int k, int x) {
	k += n;
	tree[k] = x;
	for (k /= 2; k >= 1; k /= 2) {
		tree[k] = tree[2*k]*tree[2*k+1];
		tree[k]%=((ll)1e9+7);
	}
}
pair<ll,int> pmax(pair<ll,int> a,pair<ll,int> b){
	if(a>b) return a;
	return b;
}
ll prod(ll a, ll b) {
	a += n; b += n;
	ll s = 1;
	while (a <= b) {
		if (a%2 == 1) {s *= tree[a++];s%=((ll)1e9+7);}
		if (b%2 == 0) {s *= tree[b--];s%=((ll)1e9+7);}
		a /= 2; b /= 2;
	}
	return s;
}

void ymodify(int k, int x) {
	if(k>2*n)exit(1);
	k += n;
	ytree[k] = {x,k-n};
	for (k /= 2; k >= 1; k /= 2) {
		ytree[k] = pmax(ytree[2*k],ytree[2*k+1]);
		ytree[k].first%=((ll)1e9+7);
	}
}
pair<ll,int> rmax(ll a,ll b){
	if(b>2*n)exit(1);
	a += n; b += n;
	pair<ll,int> s = {0,0};
	while (a <= b) {
		if (a%2 == 1) {s = pmax(s,ytree[a++]);}
		if (b%2 == 0) {s = pmax(s,ytree[b--]);}
		a /= 2; b /= 2;
	}
	return s;
}


int init(int N, int X[], int Y[]) {
	n=N;
	if(n<=1000)subtask3=0;
	for(int i=0;i<n;i++){
		x[i]=X[i];
		if(x[i]<2)subtask3=0;
		modify(i,x[i]);
		y[i]=Y[i];
		ymodify(i,y[i]);
		if(x[i]>1)g1.insert(i);
	}
	//if(subtask3)exit(1);
	//cout<<rmax(2,2)<<endl;;
//for(int i=0;i<2*n;i++){cerr<<ytree[i].first<<' '<<ytree[i].second<<endl;}
	if(!subtask3){
		ll mp=0;ll c=1;
		for(int i=1;i<n;i++){
			c*=x[i];
			if(c>y[mp]||y[i]>y[mp]||c*y[i]>y[mp]){mp=i;c=1;}
		}
		return (prod(0,mp)*y[mp])%((ll)1e9+7);
	}
	else{
		ll mp=n-33;ll c=1;
		for(int i=n-32;i<n;i++){
			c*=x[i];
			if(c>y[mp]||y[i]>y[mp]||c*y[i]>y[mp]){mp=i;c=1;}
		}
		return (prod(0,mp)*y[mp])%((ll)1e9+7);
	}


	
}

int sc=500;
int updateX(int pos, int val) {	
	//cerr<<pos<<endl;
	if(val==1&&g1.count(pos))g1.erase(pos);
	if(val>1)g1.insert(pos);
		x[pos]=val;

	sc--;
	//if(g1.empty())exit(1);
	if(sc==0){for(int i=0;i<n;i++)if(rmax(i,i).second!=i)exit(1);sc=3000;}
		modify(pos,val);

if(g1.empty()){
		int mp=rmax(0,n-1).second;
		return (prod(0,mp)*y[mp])%((ll)1e9+7);
	}

		ll c=x[0];ll mp=0;
		vector<int> vv;int cn=34;
		for(auto i:g1){vv.push_back(i);cn--;if(cn==0)break;}//vv.push_back(0);
		reverse(vv.begin(),vv.end());
		mp=rmax(0,vv[0]).second;
		for(int vvi=0;vvi<vv.size();vvi++){
			int vi=vv[vvi];
			int vni=n-1;if(vvi!=vv.size()-1)vni=vv[vvi+1]-1;
			int i=rmax(vi,vni).second;
			if(i>=n)exit(1);
			c*=x[vi];
			if(c>y[mp]||y[i]>y[mp]||c*y[i]>y[mp]){mp=i;c=1;}
		}
		return (prod(0,mp)*y[mp])%((ll)1e9+7);
	
}
 
int updateY(int pos, int val) {
	
		y[pos]=val;
		ymodify(pos,val);

	if(g1.empty()){
		int mp=rmax(0,n-1).second;
		//cerr<<mp<<endl;
		return (prod(0,mp)*y[mp])%((ll)1e9+7);
	}

		ll c=x[0];ll mp=0;
		vector<int> vv;int cn=34;
		for(auto i:g1){vv.push_back(i);cn--;if(cn==0)break;}//vv.push_back(0);
		reverse(vv.begin(),vv.end());
		mp=rmax(0,vv[0]).second;
		for(int vvi=0;vvi<vv.size();vvi++){
			int vi=vv[vvi];
			int vni=n-1;if(vvi!=vv.size()-1)vni=vv[vvi+1]-1;
			int i=rmax(vi,vni).second;
			if(i>=n)exit(1);
			c*=x[vi];
			if(c>y[mp]||y[i]>y[mp]||c*y[i]>y[mp]){mp=i;c=1;}
		}
		return (prod(0,mp)*y[mp])%((ll)1e9+7);
}

Compilation message

horses.cpp: In function 'void modify(int, int)':
horses.cpp:13:24: warning: declaration of 'x' shadows a global declaration [-Wshadow]
   13 | void modify(int k, int x) {
      |                    ~~~~^
horses.cpp:6:4: note: shadowed declaration is here
    6 | ll x[500001];
      |    ^
horses.cpp: In function 'void ymodify(int, int)':
horses.cpp:36:25: warning: declaration of 'x' shadows a global declaration [-Wshadow]
   36 | void ymodify(int k, int x) {
      |                     ~~~~^
horses.cpp:6:4: note: shadowed declaration is here
    6 | ll x[500001];
      |    ^
horses.cpp: In function 'std::pair<long long unsigned int, int> rmax(ll, ll)':
horses.cpp:46:6: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long unsigned int'} and 'int' [-Wsign-compare]
   46 |  if(b>2*n)exit(1);
      |     ~^~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:64:15: warning: conversion from 'll' {aka 'long long unsigned int'} to 'int' may change value [-Wconversion]
   64 |   modify(i,x[i]);
      |            ~~~^
horses.cpp:66:16: warning: conversion from 'll' {aka 'long long unsigned int'} to 'int' may change value [-Wconversion]
   66 |   ymodify(i,y[i]);
      |             ~~~^
horses.cpp:78:28: warning: conversion from 'll' {aka 'long long unsigned int'} to 'int' may change value [-Wconversion]
   78 |   return (prod(0,mp)*y[mp])%((ll)1e9+7);
      |          ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
horses.cpp:86:28: warning: conversion from 'll' {aka 'long long unsigned int'} to 'int' may change value [-Wconversion]
   86 |   return (prod(0,mp)*y[mp])%((ll)1e9+7);
      |          ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:107:28: warning: conversion from 'll' {aka 'long long unsigned int'} to 'int' may change value [-Wconversion]
  107 |   return (prod(0,mp)*y[mp])%((ll)1e9+7);
      |          ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
horses.cpp:115:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  115 |   for(int vvi=0;vvi<vv.size();vvi++){
      |                 ~~~^~~~~~~~~~
horses.cpp:117:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  117 |    int vni=n-1;if(vvi!=vv.size()-1)vni=vv[vvi+1]-1;
      |                   ~~~^~~~~~~~~~~~~
horses.cpp:123:28: warning: conversion from 'll' {aka 'long long unsigned int'} to 'int' may change value [-Wconversion]
  123 |   return (prod(0,mp)*y[mp])%((ll)1e9+7);
      |          ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:135:28: warning: conversion from 'll' {aka 'long long unsigned int'} to 'int' may change value [-Wconversion]
  135 |   return (prod(0,mp)*y[mp])%((ll)1e9+7);
      |          ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
horses.cpp:143:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  143 |   for(int vvi=0;vvi<vv.size();vvi++){
      |                 ~~~^~~~~~~~~~
horses.cpp:145:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  145 |    int vni=n-1;if(vvi!=vv.size()-1)vni=vv[vvi+1]-1;
      |                   ~~~^~~~~~~~~~~~~
horses.cpp:151:28: warning: conversion from 'll' {aka 'long long unsigned int'} to 'int' may change value [-Wconversion]
  151 |   return (prod(0,mp)*y[mp])%((ll)1e9+7);
      |          ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 312 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 312 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 216 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 312 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 312 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 312 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 3 ms 340 KB Output is correct
24 Correct 2 ms 428 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 2 ms 472 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 2 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 338 ms 63708 KB Output is correct
2 Correct 490 ms 64472 KB Output is correct
3 Correct 414 ms 63676 KB Output is correct
4 Correct 476 ms 67152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 316 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 312 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 312 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 320 KB Output is correct
23 Correct 2 ms 328 KB Output is correct
24 Correct 2 ms 328 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 174 ms 39636 KB Output is correct
34 Correct 160 ms 39620 KB Output is correct
35 Correct 271 ms 70256 KB Output is correct
36 Correct 261 ms 69956 KB Output is correct
37 Correct 153 ms 37824 KB Output is correct
38 Correct 181 ms 50500 KB Output is correct
39 Correct 148 ms 37624 KB Output is correct
40 Correct 263 ms 64976 KB Output is correct
41 Correct 138 ms 37664 KB Output is correct
42 Correct 143 ms 37684 KB Output is correct
43 Correct 239 ms 65364 KB Output is correct
44 Correct 249 ms 65404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 316 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 312 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 312 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 320 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 2 ms 328 KB Output is correct
25 Correct 2 ms 460 KB Output is correct
26 Correct 2 ms 452 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 1 ms 320 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 1 ms 328 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 319 ms 63800 KB Output is correct
34 Correct 461 ms 72592 KB Output is correct
35 Correct 410 ms 63712 KB Output is correct
36 Correct 471 ms 67608 KB Output is correct
37 Correct 147 ms 39612 KB Output is correct
38 Correct 130 ms 39584 KB Output is correct
39 Correct 295 ms 69996 KB Output is correct
40 Correct 279 ms 69896 KB Output is correct
41 Correct 162 ms 37852 KB Output is correct
42 Correct 187 ms 50548 KB Output is correct
43 Correct 149 ms 37600 KB Output is correct
44 Correct 280 ms 64984 KB Output is correct
45 Correct 142 ms 37612 KB Output is correct
46 Correct 168 ms 37676 KB Output is correct
47 Correct 263 ms 65356 KB Output is correct
48 Correct 265 ms 65316 KB Output is correct
49 Correct 351 ms 42664 KB Output is correct
50 Correct 335 ms 42580 KB Output is correct
51 Correct 403 ms 71852 KB Output is correct
52 Correct 361 ms 71364 KB Output is correct
53 Correct 325 ms 40904 KB Output is correct
54 Correct 349 ms 54504 KB Output is correct
55 Correct 268 ms 38676 KB Output is correct
56 Correct 435 ms 66732 KB Output is correct
57 Correct 201 ms 39216 KB Output is correct
58 Correct 252 ms 39792 KB Output is correct
59 Correct 243 ms 65316 KB Output is correct