답안 #571895

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
571895 2022-06-03T05:59:42 Z CSQ31 말 (IOI15_horses) C++17
100 / 100
792 ms 52308 KB
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define sz(v) (int)(v.size())
const int MAXN = 5e5+5,MOD = 1e9+7;
ll x[MAXN],y[MAXN],bit[MAXN];
int n;
int binpow(int n,int k){
	int res = 1;
	while(k){
		if(k&1)res = res * 1LL *n%MOD;
		n = n*1LL*n%MOD;
		k/=2;
	}
	return res;
}
void upd(int i,int val){
	int j = i;
	int c = binpow(x[i],MOD-2) * 1LL * val%MOD;
	for(;i<=n;i+=i&(-i))bit[i] = bit[i] * 1LL *c %MOD;
	x[j] = val;
}
int query(int i){
	int res = 1;
	for(;i>0;i-=i&(-i))res = res * 1LL * bit[i]%MOD;
	return res;
}
int t[4*MAXN];
set<int,greater<int>>pip;
void upd(int v,int l,int r,int pos,int x){
	if(l==r){
		t[v] = x;
		return;
	}
	int tm = (l+r)/2;
	if(pos<=tm)upd(2*v,l,tm,pos,x);
	else upd(2*v+1,tm+1,r,pos,x);
	t[v] = max(t[2*v],t[2*v+1]);
}
int query(int v,int l,int r,int tl,int tr){
	if(l>r)return 0;
	if(l==tl && r==tr)return t[v];
	int tm = (tl+tr)/2;
	int a = query(2*v,l,min(r,tm),tl,tm);
	int b = query(2*v+1,max(tm+1,l),r,tm+1,tr);
	return max(a,b);
}
void build(int v,int l,int r){
	if(l==r)t[v] = y[l];
	else{
		int tm = (l+r)/2;
		build(2*v,l,tm);
		build(2*v+1,tm+1,r);
		t[v] = max(t[2*v],t[2*v+1]);
	}
	
}
ll smort(){
	vector<int>v;
	for(int x:pip){
		if(sz(v)>30)break;
		v.push_back(x);
	}
	if(v.empty())return t[1];
	if(sz(v)<=30 && v.back() != 1)v.push_back(1);
	reverse(v.begin(),v.end());
	v.push_back(n+1);
	int m = sz(v);
	vector<ll>Y(m,0);
    for(int i=0;i<m-1;i++)Y[i] = query(1,v[i],v[i+1]-1,1,n);
	int last = 0;
	ll cur = 1;
	for(int i=1;i+1<m;i++){
		cur*=x[v[i]];
		if(cur > Y[last]){
			cur = 1;
			last = i;
			continue;
		} 
		if(cur * Y[i] > Y[last]){
			cur = 1;
			last = i;
		}
	}
	ll ans = query(v[last]);
	ans = ans*Y[last]%MOD;
	return ans;	
}
int init(int N, int X[], int Y[]) {
	n = N;
	for(int i=1;i<=n;i++){
		x[i] = X[i-1];
		y[i] = Y[i-1];
	}
	for(int i=1;i<=n;i++)bit[i] = 1;
	for(int i=1;i<=n;i++){
		int tmp = x[i];
		x[i] = 1;
		upd(i,tmp);
		if(x[i]>1)pip.insert(i);
	}
	build(1,1,n);
	return smort();
}

int updateX(int pos, int val) {	
	pos++;
	upd(pos,val);
	if(val > 1)pip.insert(pos);
	else if(pip.count(pos))pip.erase(pos);
	return smort();
}

int updateY(int pos, int val) {
	pos++;
	y[pos] = val;
	upd(1,1,n,pos,val);
	return smort();
}

Compilation message

horses.cpp: In function 'int binpow(int, int)':
horses.cpp:9:16: warning: declaration of 'n' shadows a global declaration [-Wshadow]
    9 | int binpow(int n,int k){
      |            ~~~~^
horses.cpp:8:5: note: shadowed declaration is here
    8 | int n;
      |     ^
horses.cpp:12:28: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   12 |   if(k&1)res = res * 1LL *n%MOD;
      |                ~~~~~~~~~~~~^~~~
horses.cpp:13:14: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   13 |   n = n*1LL*n%MOD;
      |       ~~~~~~~^~~~
horses.cpp: In function 'void upd(int, int)':
horses.cpp:20:20: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   20 |  int c = binpow(x[i],MOD-2) * 1LL * val%MOD;
      |                 ~~~^
horses.cpp:20:40: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   20 |  int c = binpow(x[i],MOD-2) * 1LL * val%MOD;
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int query(int)':
horses.cpp:26:45: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   26 |  for(;i>0;i-=i&(-i))res = res * 1LL * bit[i]%MOD;
      |                           ~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'void upd(int, int, int, int, int)':
horses.cpp:31:40: warning: declaration of 'x' shadows a global declaration [-Wshadow]
   31 | void upd(int v,int l,int r,int pos,int x){
      |                                    ~~~~^
horses.cpp:7:4: note: shadowed declaration is here
    7 | ll x[MAXN],y[MAXN],bit[MAXN];
      |    ^
horses.cpp: In function 'void build(int, int, int)':
horses.cpp:50:20: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   50 |  if(l==r)t[v] = y[l];
      |                 ~~~^
horses.cpp: In function 'll smort()':
horses.cpp:61:10: warning: declaration of 'x' shadows a global declaration [-Wshadow]
   61 |  for(int x:pip){
      |          ^
horses.cpp:7:4: note: shadowed declaration is here
    7 | ll x[MAXN],y[MAXN],bit[MAXN];
      |    ^
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:98:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   98 |   int tmp = x[i];
      |             ~~~^
horses.cpp:104:14: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  104 |  return smort();
      |         ~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:112:14: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  112 |  return smort();
      |         ~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:119:14: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  119 |  return smort();
      |         ~~~~~^~
# 결과 실행 시간 메모리 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 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 1 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 1 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 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 304 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 304 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 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 1 ms 212 KB Output is correct
13 Correct 0 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 1 ms 340 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 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 1 ms 212 KB Output is correct
23 Correct 5 ms 340 KB Output is correct
24 Correct 4 ms 340 KB Output is correct
25 Correct 4 ms 340 KB Output is correct
26 Correct 4 ms 340 KB Output is correct
27 Correct 3 ms 340 KB Output is correct
28 Correct 4 ms 340 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 3 ms 340 KB Output is correct
31 Correct 3 ms 340 KB Output is correct
32 Correct 3 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 644 ms 45408 KB Output is correct
2 Correct 744 ms 52308 KB Output is correct
3 Correct 717 ms 48264 KB Output is correct
4 Correct 781 ms 52164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 0 ms 212 KB Output is correct
5 Correct 0 ms 300 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 312 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 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 ms 312 KB Output is correct
22 Correct 0 ms 288 KB Output is correct
23 Correct 4 ms 340 KB Output is correct
24 Correct 4 ms 340 KB Output is correct
25 Correct 4 ms 340 KB Output is correct
26 Correct 4 ms 340 KB Output is correct
27 Correct 3 ms 340 KB Output is correct
28 Correct 4 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 4 ms 440 KB Output is correct
31 Correct 3 ms 324 KB Output is correct
32 Correct 3 ms 340 KB Output is correct
33 Correct 182 ms 20760 KB Output is correct
34 Correct 167 ms 24164 KB Output is correct
35 Correct 302 ms 51284 KB Output is correct
36 Correct 306 ms 51164 KB Output is correct
37 Correct 172 ms 22408 KB Output is correct
38 Correct 213 ms 35128 KB Output is correct
39 Correct 125 ms 22120 KB Output is correct
40 Correct 291 ms 49628 KB Output is correct
41 Correct 140 ms 22092 KB Output is correct
42 Correct 160 ms 22144 KB Output is correct
43 Correct 246 ms 49900 KB Output is correct
44 Correct 265 ms 49876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 212 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 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 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 312 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 308 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 308 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 312 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 308 KB Output is correct
23 Correct 4 ms 400 KB Output is correct
24 Correct 4 ms 320 KB Output is correct
25 Correct 4 ms 340 KB Output is correct
26 Correct 4 ms 340 KB Output is correct
27 Correct 4 ms 340 KB Output is correct
28 Correct 4 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 4 ms 340 KB Output is correct
31 Correct 3 ms 340 KB Output is correct
32 Correct 4 ms 340 KB Output is correct
33 Correct 635 ms 46692 KB Output is correct
34 Correct 753 ms 50468 KB Output is correct
35 Correct 721 ms 48248 KB Output is correct
36 Correct 792 ms 50160 KB Output is correct
37 Correct 184 ms 24200 KB Output is correct
38 Correct 170 ms 24284 KB Output is correct
39 Correct 301 ms 48588 KB Output is correct
40 Correct 295 ms 48096 KB Output is correct
41 Correct 177 ms 22276 KB Output is correct
42 Correct 211 ms 35120 KB Output is correct
43 Correct 135 ms 22112 KB Output is correct
44 Correct 290 ms 47812 KB Output is correct
45 Correct 154 ms 22148 KB Output is correct
46 Correct 162 ms 22144 KB Output is correct
47 Correct 247 ms 47308 KB Output is correct
48 Correct 240 ms 47324 KB Output is correct
49 Correct 678 ms 25776 KB Output is correct
50 Correct 594 ms 25696 KB Output is correct
51 Correct 700 ms 47692 KB Output is correct
52 Correct 731 ms 47380 KB Output is correct
53 Correct 702 ms 25148 KB Output is correct
54 Correct 669 ms 38072 KB Output is correct
55 Correct 227 ms 23180 KB Output is correct
56 Correct 720 ms 47308 KB Output is correct
57 Correct 480 ms 23744 KB Output is correct
58 Correct 643 ms 23696 KB Output is correct
59 Correct 262 ms 45996 KB Output is correct