답안 #832530

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
832530 2023-08-21T11:12:23 Z aymanrs 말 (IOI15_horses) C++14
100 / 100
874 ms 53200 KB
#include<bits/stdc++.h>
#define L(i) (i<<1)
#define R(i) (i<<1|1)
const int MOD = 1e9+7;
using namespace std;
long long binp(long long a, int n){
	int r = 1;
	while(n){
		if(n&1) r = a*r%MOD;
		a = a*a%MOD;
		n>>=1;
	}
	return r;
}
set<int> s;
vector<int> x, y;
const int nx = 5e5+10;
int st[4*nx], ind;
long long BIT[nx+1];
int que(int i){
	int ans = y[i-1];
	while(i){
		ans = (BIT[i]*ans)%MOD;
		i -= i&-i;
	}
	return ans;
}
void up(int i, int n, int v){
	while(i <= n){
		BIT[i] = BIT[i]*v%MOD;
		i += i&-i;
	}
}
void cons(int i, int l, int r){
	if(l==r){
		st[i] = l;
		return;
	}	
	int mid = l+r>>1;
	cons(L(i), l, mid);
	cons(R(i), mid+1, r);
	auto p = s.lower_bound(st[L(i)]+1);
	long long f = y[st[R(i)]];
	while(p!=s.end() && *p <= st[R(i)] && f <= y[st[L(i)]]){
		f *= x[*p];
		p++;
	}
	if(f <= y[st[L(i)]]) st[i] = st[L(i)];
	else st[i] = st[R(i)];
}
void upd(int i, int l, int r){
	if(l==r) return;
	int mid = l+r>>1;
	if(ind > mid) upd(R(i), mid+1, r);
	else upd(L(i),l,mid);
	auto p = s.lower_bound(st[L(i)]+1);
	long long f = y[st[R(i)]];
	while(p!=s.end() && *p <= st[R(i)] && f <= y[st[L(i)]]){
		f *= x[*p];
		p++;
	}
	if(f <= y[st[L(i)]]) st[i] = st[L(i)];
	else st[i] = st[R(i)];
}
int init(int N, int X[], int Y[]){
	fill(BIT, BIT+N+1, 1);
	for(int i = 0;i < N;i++){
		x.push_back(X[i]);
		y.push_back(Y[i]);
		if(X[i] > 1) {
			s.insert(i);
			up(i+1, N, X[i]);
		}
	}
	cons(1, 0, N-1);
	return que(st[1]+1);
}
int updateX(int pos, int val){
	up(pos+1, x.size(), val*binp(x[pos], MOD-2)%MOD);
	if((val > 1) ^ (x[pos] > 1)){
		if(x[pos] > 1) s.erase(pos);
		else s.insert(pos);
	}
	x[pos] = val;
	ind = pos;
	upd(1, 0, x.size()-1);
	return que(st[1]+1);
}
int updateY(int pos, int val){
	y[pos] = val;
	ind = pos;
	upd(1, 0, x.size()-1);
	return que(st[1]+1);
}

Compilation message

horses.cpp: In function 'long long int binp(long long int, int)':
horses.cpp:9:18: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
    9 |   if(n&1) r = a*r%MOD;
      |               ~~~^~~~
horses.cpp: In function 'int que(int)':
horses.cpp:23:21: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   23 |   ans = (BIT[i]*ans)%MOD;
      |         ~~~~~~~~~~~~^~~~
horses.cpp: In function 'void cons(int, int, int)':
horses.cpp:39:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   39 |  int mid = l+r>>1;
      |            ~^~
horses.cpp: In function 'void upd(int, int, int)':
horses.cpp:53:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   53 |  int mid = l+r>>1;
      |            ~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:79:18: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   79 |  up(pos+1, x.size(), val*binp(x[pos], MOD-2)%MOD);
      |            ~~~~~~^~
horses.cpp:79:45: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   79 |  up(pos+1, x.size(), val*binp(x[pos], MOD-2)%MOD);
      |                      ~~~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp:86:20: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   86 |  upd(1, 0, x.size()-1);
      |            ~~~~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:92:20: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   92 |  upd(1, 0, x.size()-1);
      |            ~~~~~~~~^~
# 결과 실행 시간 메모리 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 308 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 304 KB Output is correct
11 Correct 0 ms 212 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 312 KB Output is correct
15 Correct 1 ms 308 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 304 KB Output is correct
19 Correct 1 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 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 1 ms 304 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 340 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 1 ms 280 KB Output is correct
14 Correct 1 ms 308 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 308 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 300 KB Output is correct
21 Correct 1 ms 312 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 320 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 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 378 ms 40676 KB Output is correct
2 Correct 763 ms 53092 KB Output is correct
3 Correct 795 ms 44332 KB Output is correct
4 Correct 747 ms 48232 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 0 ms 212 KB Output is correct
5 Correct 0 ms 300 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 212 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 312 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 308 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 304 KB Output is correct
18 Correct 0 ms 304 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 212 KB Output is correct
22 Correct 0 ms 304 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 320 KB Output is correct
29 Correct 1 ms 316 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 48 ms 20256 KB Output is correct
34 Correct 48 ms 20328 KB Output is correct
35 Correct 220 ms 50476 KB Output is correct
36 Correct 245 ms 50480 KB Output is correct
37 Correct 37 ms 18640 KB Output is correct
38 Correct 135 ms 31184 KB Output is correct
39 Correct 25 ms 18324 KB Output is correct
40 Correct 205 ms 45540 KB Output is correct
41 Correct 23 ms 18480 KB Output is correct
42 Correct 25 ms 18532 KB Output is correct
43 Correct 191 ms 45976 KB Output is correct
44 Correct 207 ms 45948 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 304 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 304 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 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 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 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 1 ms 292 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 308 KB Output is correct
23 Correct 1 ms 320 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 316 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 376 KB Output is correct
33 Correct 381 ms 44356 KB Output is correct
34 Correct 826 ms 53200 KB Output is correct
35 Correct 874 ms 44376 KB Output is correct
36 Correct 791 ms 48316 KB Output is correct
37 Correct 45 ms 20232 KB Output is correct
38 Correct 42 ms 20388 KB Output is correct
39 Correct 231 ms 50548 KB Output is correct
40 Correct 212 ms 50432 KB Output is correct
41 Correct 31 ms 18516 KB Output is correct
42 Correct 134 ms 31204 KB Output is correct
43 Correct 23 ms 18396 KB Output is correct
44 Correct 199 ms 45588 KB Output is correct
45 Correct 23 ms 18408 KB Output is correct
46 Correct 25 ms 18556 KB Output is correct
47 Correct 184 ms 45936 KB Output is correct
48 Correct 186 ms 45932 KB Output is correct
49 Correct 242 ms 23240 KB Output is correct
50 Correct 257 ms 23324 KB Output is correct
51 Correct 427 ms 52456 KB Output is correct
52 Correct 360 ms 51960 KB Output is correct
53 Correct 165 ms 21584 KB Output is correct
54 Correct 341 ms 35068 KB Output is correct
55 Correct 66 ms 19480 KB Output is correct
56 Correct 376 ms 47460 KB Output is correct
57 Correct 58 ms 20144 KB Output is correct
58 Correct 77 ms 20588 KB Output is correct
59 Correct 184 ms 45948 KB Output is correct