Submission #774534

# Submission time Handle Problem Language Result Execution time Memory
774534 2023-07-05T19:22:17 Z 1ne Horses (IOI15_horses) C++14
34 / 100
1500 ms 47408 KB
#include "horses.h"	
#include <bits/stdc++.h>
using namespace std;
vector<long long>cur;
const int mod = 1e9 + 7;
long long inf = 1e9 + 5;
vector<long long>x,y;
long long ans = 1;
struct dataa{
	long long vx = 1,vy = 1,ans = 1,vxx = 1;
	void add(long long left,long long right,long long val,int op){
		if (op == 1){
			vx = val;
			vxx = val;
		} 
		else{
			vy = val;
		}
		ans = min(inf,vx * vy);
		//sum += val *(right - left + 1);
	}
};
long long power(long long a,long long b){
        
     long long result =1;
       while(b>0){
         if(b&1)result=(result*a)%mod; //if you want you can add mod here!
          a=(a*a)%mod; //here also.
          b>>=1;// shifted one bit similar to divide by 2 :)
      }
 return result;}
 //if m is prime then a^n = a^(n%(mod-1));
struct Segment_Tree{
	vector<dataa>tree;
	void build(long long node,long long left,long long right,vector<long long>&arr,vector<long long>&brr,long long n){
		if (left == right){
			tree[node].vx = arr[left];
			tree[node].vy = brr[left];
			tree[node].ans = min(inf,arr[left] * brr[left]);
			tree[node].vxx = arr[left];
			return ;
		}
		long long mid = (left + right)>>1;
		long long z = node + ((mid - left + 1)<<1);
		build(node + 1,left,mid,arr,brr,n);
		build(z,mid + 1,right,arr,brr,n);
		tree[node] = combine(tree[node + 1],tree[z]);
	}
	void init(long long n,vector<long long>&arr,vector<long long>&brr){
		tree.resize(2*n - 1);
		build(0,0,n-1,arr,brr,n);
	}
	dataa combine(dataa left,dataa right){
		dataa res;
		res.vx = min(left.vx * right.vx,inf);
		res.vy = right.vy;
		res.ans = max(left.ans,min(left.vx * right.ans,inf));
		res.vxx = (left.vxx * right.vxx)%mod;
		return res;
	}
	dataa query(long long node,long long left,long long right,long long qleft,long long qright){
		if (qright<left|| qleft > right)return {1,1,1,1};
		if (qleft<=left && qright>=right){
			return tree[node];
		}
		long long mid = (left + right)>>1;
		long long z = node + ((mid - left + 1)<<1);
		return combine(query(node + 1,left,mid,qleft,qright),query(z,mid + 1,right,qleft,qright));
	}
	void update(long long node,long long left,long long right,long long uleft,long long uright,long long v,int op){
		if (left > uright || right < uleft) return;
		if (uleft <= left && right <=uright){
			tree[node].add(left,right,v,op);
			return;
		}
		long long mid = (left + right)>>1;
		long long z = node + ((mid - left + 1)<<1);
		if (uleft<=mid){
			update(node + 1,left,mid,uleft,uright,v,op);
		}
		if (uright > mid){
			update(z,mid + 1,right,uleft,uright,v,op);
		}
		tree[node] = combine(tree[node + 1],tree[z]);
	}
};
int n;
int valid = -1;
Segment_Tree st;	
int init(int N, int X[], int Y[]) {
	cur.resize(N);
	n = N;
	for (int i = 0;i<n;++i){
		x.push_back(X[i]);
		y.push_back(Y[i]);
	}
	st.init(n,x,y);
	long long v = 1;
	for (int i = 0;i<N;++i){
		bool ok = true;
		long long u = 1;
		if (st.query(0,0,n - 1,i + 1,n - 1).ans > y[i]){
			ok = false;
		}
		v = (v * x[i])%mod;
		if (ok){
			valid = i;
			return ans = (v * y[i])%mod;
		}
	}
//	return 0;	
}
 
int updateX(int pos, int val) {
	st.update(0,0,n - 1,pos,pos,val,1);	
	if (pos <= valid){
		ans = ((ans * power(x[pos],mod - 2))%mod * val)%mod;
		x[pos] = val;
		ans = x[0];
		valid = 0;
		while(valid < n - 1 && st.query(0,0,n - 1,valid + 1,n - 1).ans > y[valid]){
			++valid;
		}
		ans = st.query(0,0,n - 1,0,valid).vxx;
		ans = (ans * y[valid]) % mod;		
	}
	else if (x[pos] >= val){
		x[pos] = val;	
	}
	else{
		ans = ((ans * power(y[valid],mod - 2))%mod);
		x[pos] = val;
		while(valid < n - 1 && st.query(0,0,n - 1,valid + 1,n - 1).ans > y[valid]){
			++valid;
			ans = (ans * x[valid])%mod;
		}
		ans = (ans * y[valid])%mod;	
	}
	return ans;
}
 
int updateY(int pos, int val) {
	st.update(0,0,n - 1,pos,pos,val,2);
	if (pos < valid){
		y[pos] = val;
		ans = x[0];
		valid = 0;
		while(valid < n - 1 && st.query(0,0,n - 1,valid + 1,n - 1).ans > y[valid]){
			++valid;
		}
		ans = st.query(0,0,n - 1,0,valid).vxx;
		ans = (ans * y[valid]) % mod;
	}
	else {
		y[pos] = val;
		ans = x[0];
		valid = 0;
		while(valid < n - 1 && st.query(0,0,n - 1,valid + 1,n - 1).ans > y[valid]){
			++valid;
			ans = (ans * x[valid])%mod;
		}
		ans = (ans * y[valid]) % mod;
	}
	return ans;	
}

Compilation message

horses.cpp: In member function 'void dataa::add(long long int, long long int, long long int, int)':
horses.cpp:11:21: warning: unused parameter 'left' [-Wunused-parameter]
   11 |  void add(long long left,long long right,long long val,int op){
      |           ~~~~~~~~~~^~~~
horses.cpp:11:36: warning: unused parameter 'right' [-Wunused-parameter]
   11 |  void add(long long left,long long right,long long val,int op){
      |                          ~~~~~~~~~~^~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:108:15: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  108 |    return ans = (v * y[i])%mod;
      |           ~~~~^~~~~~~~~~~~~~~~
horses.cpp:101:13: warning: unused variable 'u' [-Wunused-variable]
  101 |   long long u = 1;
      |             ^
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:139:9: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  139 |  return ans;
      |         ^~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:164:9: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  164 |  return ans;
      |         ^~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:112:1: warning: control reaches end of non-void function [-Wreturn-type]
  112 | }
      | ^
# 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 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 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 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 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
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 296 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 256 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 63 ms 400 KB Output is correct
24 Correct 64 ms 388 KB Output is correct
25 Correct 33 ms 400 KB Output is correct
26 Correct 64 ms 396 KB Output is correct
27 Correct 57 ms 400 KB Output is correct
28 Correct 63 ms 380 KB Output is correct
29 Correct 38 ms 440 KB Output is correct
30 Correct 45 ms 380 KB Output is correct
31 Correct 16 ms 408 KB Output is correct
32 Correct 36 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1580 ms 47408 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 232 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 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 224 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 63 ms 340 KB Output is correct
24 Correct 64 ms 340 KB Output is correct
25 Correct 34 ms 340 KB Output is correct
26 Correct 64 ms 340 KB Output is correct
27 Correct 57 ms 396 KB Output is correct
28 Correct 60 ms 404 KB Output is correct
29 Correct 33 ms 340 KB Output is correct
30 Correct 48 ms 376 KB Output is correct
31 Correct 15 ms 340 KB Output is correct
32 Correct 36 ms 396 KB Output is correct
33 Execution timed out 1590 ms 47408 KB Time limit exceeded
34 Halted 0 ms 0 KB -
# 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 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 216 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 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 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 67 ms 404 KB Output is correct
24 Correct 69 ms 340 KB Output is correct
25 Correct 33 ms 396 KB Output is correct
26 Correct 65 ms 400 KB Output is correct
27 Correct 57 ms 400 KB Output is correct
28 Correct 61 ms 340 KB Output is correct
29 Correct 33 ms 340 KB Output is correct
30 Correct 46 ms 400 KB Output is correct
31 Correct 16 ms 340 KB Output is correct
32 Correct 36 ms 404 KB Output is correct
33 Execution timed out 1587 ms 47400 KB Time limit exceeded
34 Halted 0 ms 0 KB -