답안 #831835

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
831835 2023-08-20T15:53:36 Z ttamx 말 (IOI15_horses) C++14
100 / 100
151 ms 70852 KB
#include "horses.h"
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N=5e5+5;
const int K=1<<20;
const ll mod=1e9+7;

int n;
int X[N],Y[N];

struct segtree{
	struct node{
		ll x,y,pre,suf,all,ans;
		node(){}
		node(ll x,ll y):x(x),y(y),pre(x),suf(1),all(x),ans(x*y%mod){}
		friend node operator+(node l,node r){
			node res;
			res.x=l.x*r.x%mod;
			res.all=min(l.all*r.all,mod);
			if(l.y>min(l.suf*r.pre,mod)*r.y){
				res.y=l.y;
				res.pre=l.pre;
				res.suf=min(l.suf*r.all,mod);
				res.ans=l.ans;
			}else{
				res.y=r.y;
				res.pre=min(l.all*r.pre,mod);
				res.suf=r.suf;
				res.ans=l.x*r.ans%mod;
			}
			return res;
		}
	}t[K];
	void build(int l,int r,int i){
		if(l==r)return void(t[i]=node(X[l],Y[l]));
		int m=(l+r)/2;
		build(l,m,i*2);
		build(m+1,r,i*2+1);
		t[i]=t[i*2]+t[i*2+1];
	}
	void build(){
		build(1,n,1);
	}
	void update(int l,int r,int i,int x){
		if(x<l||r<x)return;
		if(l==r)return void(t[i]=node(X[l],Y[l]));
		int m=(l+r)/2;
		update(l,m,i*2,x);
		update(m+1,r,i*2+1,x);
		t[i]=t[i*2]+t[i*2+1];
	}
	void update(int x){
		update(1,n,1,x);
	}
}s;

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];
	s.build();
	return s.t[1].ans;
}

int updateX(int pos, int val) {
	pos++;
	X[pos]=val;
	s.update(pos);
	return s.t[1].ans;
}

int updateY(int pos, int val) {
	pos++;
	Y[pos]=val;
	s.update(pos);
	return s.t[1].ans;
}

Compilation message

horses.cpp: In constructor 'segtree::node::node(ll, ll)':
horses.cpp:19:16: warning: declaration of 'y' shadows a member of 'segtree::node' [-Wshadow]
   19 |   node(ll x,ll y):x(x),y(y),pre(x),suf(1),all(x),ans(x*y%mod){}
      |             ~~~^
horses.cpp:17:8: note: shadowed declaration is here
   17 |   ll x,y,pre,suf,all,ans;
      |        ^
horses.cpp:19:11: warning: declaration of 'x' shadows a member of 'segtree::node' [-Wshadow]
   19 |   node(ll x,ll y):x(x),y(y),pre(x),suf(1),all(x),ans(x*y%mod){}
      |        ~~~^
horses.cpp:17:6: note: shadowed declaration is here
   17 |   ll x,y,pre,suf,all,ans;
      |      ^
horses.cpp: In constructor 'segtree::node::node(ll, ll)':
horses.cpp:19:16: warning: declaration of 'y' shadows a member of 'segtree::node' [-Wshadow]
   19 |   node(ll x,ll y):x(x),y(y),pre(x),suf(1),all(x),ans(x*y%mod){}
      |             ~~~^
horses.cpp:17:8: note: shadowed declaration is here
   17 |   ll x,y,pre,suf,all,ans;
      |        ^
horses.cpp:19:11: warning: declaration of 'x' shadows a member of 'segtree::node' [-Wshadow]
   19 |   node(ll x,ll y):x(x),y(y),pre(x),suf(1),all(x),ans(x*y%mod){}
      |        ~~~^
horses.cpp:17:6: note: shadowed declaration is here
   17 |   ll x,y,pre,suf,all,ans;
      |      ^
horses.cpp: In constructor 'segtree::node::node(ll, ll)':
horses.cpp:19:16: warning: declaration of 'y' shadows a member of 'segtree::node' [-Wshadow]
   19 |   node(ll x,ll y):x(x),y(y),pre(x),suf(1),all(x),ans(x*y%mod){}
      |             ~~~^
horses.cpp:17:8: note: shadowed declaration is here
   17 |   ll x,y,pre,suf,all,ans;
      |        ^
horses.cpp:19:11: warning: declaration of 'x' shadows a member of 'segtree::node' [-Wshadow]
   19 |   node(ll x,ll y):x(x),y(y),pre(x),suf(1),all(x),ans(x*y%mod){}
      |        ~~~^
horses.cpp:17:6: note: shadowed declaration is here
   17 |   ll x,y,pre,suf,all,ans;
      |      ^
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:65:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   65 |  return s.t[1].ans;
      |         ~~~~~~~^~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:72:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   72 |  return s.t[1].ans;
      |         ~~~~~~~^~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:79:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   79 |  return s.t[1].ans;
      |         ~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 312 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 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 0 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 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 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 1 ms 256 KB Output is correct
# 결과 실행 시간 메모리 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 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 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 312 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 308 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 308 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 448 KB Output is correct
30 Correct 1 ms 460 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 62116 KB Output is correct
2 Correct 151 ms 70848 KB Output is correct
3 Correct 119 ms 62044 KB Output is correct
4 Correct 133 ms 65976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 308 KB Output is correct
4 Correct 0 ms 312 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 248 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 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 312 KB Output is correct
23 Correct 1 ms 432 KB Output is correct
24 Correct 1 ms 464 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 452 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 53 ms 61504 KB Output is correct
34 Correct 54 ms 61328 KB Output is correct
35 Correct 67 ms 68292 KB Output is correct
36 Correct 68 ms 68276 KB Output is correct
37 Correct 42 ms 59536 KB Output is correct
38 Correct 41 ms 60364 KB Output is correct
39 Correct 41 ms 59360 KB Output is correct
40 Correct 51 ms 63292 KB Output is correct
41 Correct 36 ms 59416 KB Output is correct
42 Correct 36 ms 59520 KB Output is correct
43 Correct 49 ms 63704 KB Output is correct
44 Correct 48 ms 63692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 308 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 312 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 0 ms 212 KB Output is correct
11 Correct 0 ms 316 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 0 ms 316 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 1 ms 340 KB Output is correct
24 Correct 1 ms 456 KB Output is correct
25 Correct 1 ms 476 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 452 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 448 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 452 KB Output is correct
33 Correct 78 ms 62068 KB Output is correct
34 Correct 144 ms 70852 KB Output is correct
35 Correct 117 ms 62148 KB Output is correct
36 Correct 141 ms 65896 KB Output is correct
37 Correct 58 ms 61384 KB Output is correct
38 Correct 51 ms 61320 KB Output is correct
39 Correct 67 ms 68328 KB Output is correct
40 Correct 73 ms 68288 KB Output is correct
41 Correct 49 ms 59480 KB Output is correct
42 Correct 41 ms 60444 KB Output is correct
43 Correct 36 ms 59408 KB Output is correct
44 Correct 50 ms 63304 KB Output is correct
45 Correct 36 ms 59392 KB Output is correct
46 Correct 37 ms 59520 KB Output is correct
47 Correct 48 ms 63708 KB Output is correct
48 Correct 49 ms 63756 KB Output is correct
49 Correct 128 ms 63384 KB Output is correct
50 Correct 136 ms 63280 KB Output is correct
51 Correct 98 ms 70084 KB Output is correct
52 Correct 98 ms 69660 KB Output is correct
53 Correct 114 ms 61668 KB Output is correct
54 Correct 78 ms 62204 KB Output is correct
55 Correct 64 ms 60512 KB Output is correct
56 Correct 82 ms 65180 KB Output is correct
57 Correct 66 ms 61196 KB Output is correct
58 Correct 67 ms 61556 KB Output is correct
59 Correct 47 ms 63624 KB Output is correct