답안 #599108

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
599108 2022-07-19T10:12:05 Z sofapuden 말 (IOI15_horses) C++14
100 / 100
563 ms 144524 KB
#include <bits/stdc++.h>
#include "horses.h"

using namespace std;

typedef long long ll;

const ll M = 1e9+7;

struct seg2 {
	struct nod {
		ll val;
		ll val2;
	};
	int n;
	vector<nod> st;
	vector<ll> A;

	seg2() {}
	seg2(int sz) : n(sz), st(4*n) {}
	seg2(vector<ll> &in) : seg2((int)in.size()) {
		A = in;
		build(0,n-1,1);
	}

	nod merge (nod a, nod b) {
		nod c;
		c.val = min(1ll<<30,a.val*b.val);
		c.val2 = a.val2*b.val2%M;
		return c;
	}
	
	void build(int l, int r, int p){
		if(l == r){
			nod c;
			c.val = A[l];
			c.val2 = A[l];
			st[p] = c;
			return;
		}
		int m = (l+r) >> 1;
		build(l,m,p<<1);
		build(m+1,r,p<<1|1);
		st[p] = merge(st[p<<1],st[p<<1|1]);
	}

	void update(int x, ll val, int l, int r, int p){
		if(l == r){
			nod c;
			c.val = val;
			c.val2 = val;
			st[p] = c;
			return;
		}
		int m = (l+r) >> 1;
		if(m >= x)update(x,val,l,m,p<<1);
		else update(x,val,m+1,r,p<<1|1);
		st[p] = merge(st[p<<1], st[p<<1|1]);
	}
	void updateno(int x, int l, int r, int p){
		if(l == r){
			return;
		}
		int m = (l+r) >> 1;
		if(m >= x)updateno(x,l,m,p<<1);
		else updateno(x,m+1,r,p<<1|1);
		st[p] = merge(st[p<<1], st[p<<1|1]);
	}

	nod que(int i, int j, int l, int r, int p){
		if(l >= i && r <= j)return st[p];
		int m = (l+r)>>1;
		if(m < i)return que(i,j,m+1,r,p<<1|1);
		else if(m >= j)return que(i,j,l,m,p<<1);
		else return merge(que(i,j,l,m,p<<1),que(i,j,m+1,r,p<<1|1));
	}
}st2;

struct seg {
	struct nod {
		int pos;
	};
	int n;
	vector<nod> st;
	vector<ll> Ax;
	vector<ll> Ay;
	seg2 stval;

	seg() {}
	seg(int sz) : n(sz), st(4*n) {}
	seg(vector<ll> &_X, vector<ll> &_Y, seg2 _stval) : seg((int)_X.size()) {
		Ax = _X;
		Ay = _Y;
		stval = _stval;
		build(0,n-1,1);
	}

	nod merge (nod a, nod b) {
		ll v1 = stval.que(a.pos+1,b.pos,0,n-1,1).val*Ay[b.pos];
		ll v2 = Ay[a.pos];
		if(v1 > v2)return b;
		else return a;
	}
	
	void build(int l, int r, int p){
		if(l == r){
			nod c;
			c.pos = l;
			st[p] = c;
			return;
		}
		int m = (l+r) >> 1;
		build(l,m,p<<1);
		build(m+1,r,p<<1|1);
		st[p] = merge(st[p<<1],st[p<<1|1]);
	}

	void update(int x, ll val, int l, int r, int p){
		if(l == r){
			Ay[l] = val;
			return;
		}
		int m = (l+r) >> 1;
		if(m >= x)update(x,val,l,m,p<<1);
		else update(x,val,m+1,r,p<<1|1);
		st[p] = merge(st[p<<1], st[p<<1|1]);
	}
	void updateno(int x, int l, int r, int p){
		if(l == r){
			return;
		}
		int m = (l+r) >> 1;
		if(m >= x)updateno(x,l,m,p<<1);
		else updateno(x,m+1,r,p<<1|1);
		st[p] = merge(st[p<<1], st[p<<1|1]);
	}

	nod que(int i, int j, int l, int r, int p){
		if(l >= i && r <= j)return st[p];
		int m = (l+r)>>1;
		if(m < i)return que(i,j,m+1,r,p<<1|1);
		else if(m >= j)return que(i,j,l,m,p<<1);
		else return merge(que(i,j,l,m,p<<1),que(i,j,m+1,r,p<<1|1));
	}
}st;

int glN;
vector<ll> x, y;

int init(int N, int X[], int Y[]) {
	glN = N;
	x.resize(N);
	y.resize(N);
	for(int i = 0; i < N; ++i){
		x[i] = X[i];
		y[i] = Y[i];
	}
	st2 = seg2(x);
	st = seg(x,y,st2);
	return (int)(st.stval.que(0,st.st[1].pos,0,glN-1,1).val2*y[st.st[1].pos]%M);
}

int updateX(int pos, int val) {	
	x[pos] = val;
	st.stval.update(pos,val,0,glN-1,1);
	st.updateno(pos,0,glN-1,1);
	return (int)(st.stval.que(0,st.st[1].pos,0,glN-1,1).val2*y[st.st[1].pos]%M);
}

int updateY(int pos, int val) {
	y[pos] = val;
	st.update(pos,val,0,glN-1,1);
	st.stval.updateno(pos,0,glN-1,1);
	return (int)(st.stval.que(0,st.st[1].pos,0,glN-1,1).val2*y[st.st[1].pos]%M);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 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 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 300 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 1 ms 212 KB Output is correct
16 Correct 1 ms 300 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
# 결과 실행 시간 메모리 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 1 ms 304 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 300 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 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 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
24 Correct 2 ms 572 KB Output is correct
25 Correct 2 ms 592 KB Output is correct
26 Correct 2 ms 596 KB Output is correct
27 Correct 3 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 468 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 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 246 ms 134156 KB Output is correct
2 Correct 356 ms 144524 KB Output is correct
3 Correct 365 ms 135500 KB Output is correct
4 Correct 352 ms 139300 KB Output is correct
# 결과 실행 시간 메모리 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 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 1 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 212 KB Output is correct
16 Correct 1 ms 212 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 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
24 Correct 2 ms 556 KB Output is correct
25 Correct 1 ms 572 KB Output is correct
26 Correct 1 ms 572 KB Output is correct
27 Correct 2 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 3 ms 468 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 2 ms 572 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 163 ms 137308 KB Output is correct
34 Correct 156 ms 137316 KB Output is correct
35 Correct 144 ms 138260 KB Output is correct
36 Correct 160 ms 138352 KB Output is correct
37 Correct 146 ms 135488 KB Output is correct
38 Correct 121 ms 136400 KB Output is correct
39 Correct 128 ms 135444 KB Output is correct
40 Correct 131 ms 138240 KB Output is correct
41 Correct 139 ms 135436 KB Output is correct
42 Correct 130 ms 135412 KB Output is correct
43 Correct 115 ms 138220 KB Output is correct
44 Correct 113 ms 138168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 308 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 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 1 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 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 1 ms 212 KB Output is correct
20 Correct 0 ms 300 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 468 KB Output is correct
24 Correct 2 ms 596 KB Output is correct
25 Correct 1 ms 596 KB Output is correct
26 Correct 1 ms 556 KB Output is correct
27 Correct 2 ms 468 KB Output is correct
28 Correct 1 ms 556 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 265 ms 135452 KB Output is correct
34 Correct 315 ms 144284 KB Output is correct
35 Correct 429 ms 135444 KB Output is correct
36 Correct 363 ms 139364 KB Output is correct
37 Correct 166 ms 137216 KB Output is correct
38 Correct 153 ms 137276 KB Output is correct
39 Correct 165 ms 144244 KB Output is correct
40 Correct 144 ms 144116 KB Output is correct
41 Correct 145 ms 135376 KB Output is correct
42 Correct 120 ms 136392 KB Output is correct
43 Correct 127 ms 135420 KB Output is correct
44 Correct 129 ms 139188 KB Output is correct
45 Correct 127 ms 135424 KB Output is correct
46 Correct 130 ms 135596 KB Output is correct
47 Correct 115 ms 139752 KB Output is correct
48 Correct 120 ms 139760 KB Output is correct
49 Correct 538 ms 137332 KB Output is correct
50 Correct 475 ms 137344 KB Output is correct
51 Correct 329 ms 144288 KB Output is correct
52 Correct 203 ms 144448 KB Output is correct
53 Correct 563 ms 135472 KB Output is correct
54 Correct 260 ms 136340 KB Output is correct
55 Correct 366 ms 135500 KB Output is correct
56 Correct 321 ms 139392 KB Output is correct
57 Correct 306 ms 135496 KB Output is correct
58 Correct 406 ms 135484 KB Output is correct
59 Correct 114 ms 139704 KB Output is correct