답안 #742521

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
742521 2023-05-16T11:24:10 Z Dan4Life 말 (IOI15_horses) C++17
100 / 100
356 ms 44420 KB
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mxN = (int)5e5+10;
const int MOD = (int)1e9+7;
struct Data{ double sum, ans; int i; } segTree[2*mxN];
ll n, X[mxN], Y[mxN], segTree2[2*mxN];

Data comb(Data &a, Data &b){
	Data c = {a.sum+b.sum,a.ans,a.i};
	if(a.ans <= a.sum+b.ans) c.i=b.i;
	c.ans = max(a.ans, a.sum+b.ans);
	return c;
}

void upd2(int x, ll v, int p=0, int l=0, int r=n-1){
	if(l==r){ segTree2[p] = v; return; }
	int mid = (l+r)/2; int rp = p+2*(mid-l+1);
	if(x<=mid) upd2(x,v,p+1,l,mid);
	else upd2(x,v,rp,mid+1,r);
	segTree2[p] = (segTree2[p+1]*segTree2[rp])%MOD;
}

ll query(int i, int j, int p=0, int l=0, int r=n-1){
	if(i>r or j<l or i>j) return 1ll;
	if(i<=l and r<=j) return segTree2[p];
	int mid = (l+r)/2; int rp = p+2*(mid-l+1);
	return (query(i,j,p+1,l,mid)*query(i,j,rp,mid+1,r))%MOD;
}

void upd(int x, ll v, int p=0, int l=0, int r=n-1){
	if(l==r){
		segTree[p] = {log(v),log(v)+log(Y[x]),x};
		X[x] = v; upd2(x,v); return;
	}
	int mid = (l+r)/2; int rp = p+2*(mid-l+1);
	if(x<=mid) upd(x,v,p+1,l,mid);
	else upd(x,v,rp,mid+1,r);
	segTree[p] = comb(segTree[p+1],segTree[rp]);
}

int init(int N, int x[], int y[]) {
	n = N;
	for(int i = 0; i < n; i++)
		X[i] = x[i], Y[i] = y[i], upd(i,X[i]);
	int i = segTree[0].i;
	return (query(0,i)*Y[i])%MOD;
}

int updateX(int x, int v) {
	upd(x,v);
	int i = segTree[0].i;
	return (query(0,i)*Y[i])%MOD;
}

int updateY(int x, int v) {
	Y[x] = v; upd(x,X[x]);
	int i = segTree[0].i;
	return (query(0,i)*Y[i])%MOD;
}

Compilation message

horses.cpp:17:49: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   17 | void upd2(int x, ll v, int p=0, int l=0, int r=n-1){
      |                                                ~^~
horses.cpp:25:49: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   25 | ll query(int i, int j, int p=0, int l=0, int r=n-1){
      |                                                ~^~
horses.cpp:32:48: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   32 | void upd(int x, ll v, int p=0, int l=0, int r=n-1){
      |                                               ~^~
horses.cpp: In function 'void upd(int, ll, int, int, int)':
horses.cpp:35:21: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   35 |   X[x] = v; upd2(x,v); return;
      |                     ^
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:46:39: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   46 |   X[i] = x[i], Y[i] = y[i], upd(i,X[i]);
      |                                       ^
horses.cpp:48:19: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   48 |  return (query(0,i)*Y[i])%MOD;
      |                   ^
horses.cpp:48:26: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   48 |  return (query(0,i)*Y[i])%MOD;
      |         ~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:52:9: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   52 |  upd(x,v);
      |         ^
horses.cpp:54:19: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   54 |  return (query(0,i)*Y[i])%MOD;
      |                   ^
horses.cpp:54:26: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   54 |  return (query(0,i)*Y[i])%MOD;
      |         ~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:58:22: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   58 |  Y[x] = v; upd(x,X[x]);
      |                      ^
horses.cpp:60:19: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   60 |  return (query(0,i)*Y[i])%MOD;
      |                   ^
horses.cpp:60:26: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   60 |  return (query(0,i)*Y[i])%MOD;
      |         ~~~~~~~~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 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 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 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 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 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 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 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 340 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 278 ms 44288 KB Output is correct
2 Correct 350 ms 44324 KB Output is correct
3 Correct 314 ms 44276 KB Output is correct
4 Correct 342 ms 44308 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 1 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 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 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 300 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 1 ms 212 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 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 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
33 Correct 248 ms 43452 KB Output is correct
34 Correct 248 ms 43424 KB Output is correct
35 Correct 250 ms 43468 KB Output is correct
36 Correct 252 ms 43424 KB Output is correct
37 Correct 233 ms 43428 KB Output is correct
38 Correct 245 ms 43560 KB Output is correct
39 Correct 215 ms 43344 KB Output is correct
40 Correct 238 ms 43380 KB Output is correct
41 Correct 222 ms 43440 KB Output is correct
42 Correct 219 ms 43340 KB Output is correct
43 Correct 229 ms 43240 KB Output is correct
44 Correct 239 ms 43420 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 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 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 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 2 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 340 KB Output is correct
28 Correct 1 ms 392 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
33 Correct 310 ms 44236 KB Output is correct
34 Correct 344 ms 44284 KB Output is correct
35 Correct 312 ms 44344 KB Output is correct
36 Correct 331 ms 44352 KB Output is correct
37 Correct 239 ms 43532 KB Output is correct
38 Correct 245 ms 43348 KB Output is correct
39 Correct 251 ms 43332 KB Output is correct
40 Correct 252 ms 43404 KB Output is correct
41 Correct 223 ms 43340 KB Output is correct
42 Correct 235 ms 43352 KB Output is correct
43 Correct 221 ms 43316 KB Output is correct
44 Correct 231 ms 43372 KB Output is correct
45 Correct 216 ms 43448 KB Output is correct
46 Correct 228 ms 43464 KB Output is correct
47 Correct 226 ms 43256 KB Output is correct
48 Correct 240 ms 43332 KB Output is correct
49 Correct 356 ms 44380 KB Output is correct
50 Correct 331 ms 44252 KB Output is correct
51 Correct 316 ms 44420 KB Output is correct
52 Correct 290 ms 44296 KB Output is correct
53 Correct 317 ms 44364 KB Output is correct
54 Correct 300 ms 44232 KB Output is correct
55 Correct 256 ms 43496 KB Output is correct
56 Correct 324 ms 44340 KB Output is correct
57 Correct 273 ms 44216 KB Output is correct
58 Correct 280 ms 44392 KB Output is correct
59 Correct 234 ms 43272 KB Output is correct