답안 #747215

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
747215 2023-05-24T00:14:32 Z Abrar_Al_Samit 말 (IOI15_horses) C++17
100 / 100
693 ms 57036 KB
#include <bits/stdc++.h>
#include "horses.h"
using namespace std;

const int nax = 5e5 + 2;
const int mod = 1e9 + 7;
const int MX = 1e9;
long long x[nax], y[nax];
int n;

long long mul(long long a, long long b) {
	return (a * b) % mod;
}
long long quickpow(long long a, long long b) {
	long long ret = 1;
	while(b) {
		if(b&1) ret = mul(ret, a);
		a = mul(a, a);
		b >>= 1;
	}
	return ret;
}


struct BIT {
	long long b[nax];
	BIT() {
		for(int i=0; i<nax; ++i) {
			b[i] = 1;
		}
	}

	void update(int p, int val) {
		while(p<nax) {
			b[p] = mul(b[p], val);
			p += p&-p;
		}
	}
	long long query(int p) {
		long long ret = 1;
		while(p) {
			ret = mul(ret, b[p]);
			p -= p&-p;
		}
		return ret;
	}

} fen;
int seg[1<<20];
void update(int pos, int val, int l=1, int r=n, int v=1) {
	if(l==r) {
		seg[v] = val;
		return;
	}
	int mid = (l+r)/2;
	if(pos<=mid) update(pos, val, l, mid, v*2);
	else update(pos, val, mid+1, r, v*2+1);
	seg[v] = max(seg[v*2], seg[v*2+1]);
}
int query(int L, int R, int l=1, int r=n, int v=1) {
	if(l>=L && r<=R) return seg[v];
	if(l>R || r<L) return 0;
	int mid = (l+r)/2;
	return max(query(L, R, l, mid, v*2), query(L, R, mid+1, r, v*2+1));
}

set<int>nonone;
int get() {
    long long ret = 0;
    int next_big = n;

    int t = 30;
    long long later = 0;
    for(auto it = prev(nonone.end()); t>0 && later<=MX; --it, --t) {
        long long price = query(*it+1, next_big);
        if(price > later) {
            later = price;

            ret = (price * fen.query(*it+1)) % mod;
        }

        if(it==nonone.begin()) break;
        later *= x[*it];
        next_big = *it;
    }

    return ret;
}
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];
		fen.update(i+1, x[i]);
		update(i+1, y[i]);

		if(x[i]>1) nonone.insert(i);
	}
    nonone.insert(0);
	return get();
}

int updateX(int pos, int val) {	
	fen.update(pos+1, quickpow(x[pos], mod-2));
	fen.update(pos+1, val);

	if(x[pos]==1 && val>1) {
		nonone.insert(pos);
	} else if(x[pos]>1 && val==1) {
		nonone.erase(pos);
	} 

	x[pos] = val;
    nonone.insert(0);

	return get();
}

int updateY(int pos, int val) {
	update(pos+1, val);
	y[pos] = val;

	return get();
}

Compilation message

horses.cpp: In function 'int get()':
horses.cpp:87:12: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   87 |     return ret;
      |            ^~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:93:22: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   93 |   fen.update(i+1, x[i]);
      |                   ~~~^
horses.cpp:94:18: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   94 |   update(i+1, y[i]);
      |               ~~~^
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:103:28: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  103 |  fen.update(pos+1, quickpow(x[pos], mod-2));
      |                    ~~~~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4180 KB Output is correct
2 Correct 2 ms 4180 KB Output is correct
3 Correct 3 ms 4180 KB Output is correct
4 Correct 3 ms 4184 KB Output is correct
5 Correct 3 ms 4140 KB Output is correct
6 Correct 3 ms 4124 KB Output is correct
7 Correct 2 ms 4180 KB Output is correct
8 Correct 2 ms 4180 KB Output is correct
9 Correct 2 ms 4180 KB Output is correct
10 Correct 2 ms 4180 KB Output is correct
11 Correct 2 ms 4180 KB Output is correct
12 Correct 2 ms 4180 KB Output is correct
13 Correct 2 ms 4180 KB Output is correct
14 Correct 2 ms 4180 KB Output is correct
15 Correct 3 ms 4228 KB Output is correct
16 Correct 2 ms 4180 KB Output is correct
17 Correct 2 ms 4180 KB Output is correct
18 Correct 2 ms 4180 KB Output is correct
19 Correct 2 ms 4180 KB Output is correct
20 Correct 2 ms 4180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4180 KB Output is correct
2 Correct 2 ms 4180 KB Output is correct
3 Correct 2 ms 4180 KB Output is correct
4 Correct 2 ms 4180 KB Output is correct
5 Correct 2 ms 4180 KB Output is correct
6 Correct 2 ms 4180 KB Output is correct
7 Correct 2 ms 4180 KB Output is correct
8 Correct 3 ms 4224 KB Output is correct
9 Correct 2 ms 4180 KB Output is correct
10 Correct 2 ms 4180 KB Output is correct
11 Correct 3 ms 4228 KB Output is correct
12 Correct 3 ms 4180 KB Output is correct
13 Correct 2 ms 4180 KB Output is correct
14 Correct 3 ms 4180 KB Output is correct
15 Correct 3 ms 4180 KB Output is correct
16 Correct 2 ms 4180 KB Output is correct
17 Correct 2 ms 4224 KB Output is correct
18 Correct 2 ms 4180 KB Output is correct
19 Correct 2 ms 4180 KB Output is correct
20 Correct 2 ms 4180 KB Output is correct
21 Correct 2 ms 4180 KB Output is correct
22 Correct 2 ms 4180 KB Output is correct
23 Correct 3 ms 4244 KB Output is correct
24 Correct 3 ms 4240 KB Output is correct
25 Correct 3 ms 4308 KB Output is correct
26 Correct 3 ms 4308 KB Output is correct
27 Correct 6 ms 4180 KB Output is correct
28 Correct 4 ms 4340 KB Output is correct
29 Correct 3 ms 4180 KB Output is correct
30 Correct 4 ms 4308 KB Output is correct
31 Correct 5 ms 4180 KB Output is correct
32 Correct 5 ms 4236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 641 ms 44588 KB Output is correct
2 Correct 300 ms 44432 KB Output is correct
3 Correct 334 ms 44492 KB Output is correct
4 Correct 296 ms 44460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4180 KB Output is correct
2 Correct 2 ms 4180 KB Output is correct
3 Correct 2 ms 4180 KB Output is correct
4 Correct 2 ms 4180 KB Output is correct
5 Correct 2 ms 4180 KB Output is correct
6 Correct 2 ms 4224 KB Output is correct
7 Correct 2 ms 4180 KB Output is correct
8 Correct 2 ms 4180 KB Output is correct
9 Correct 3 ms 4228 KB Output is correct
10 Correct 2 ms 4180 KB Output is correct
11 Correct 2 ms 4180 KB Output is correct
12 Correct 2 ms 4180 KB Output is correct
13 Correct 3 ms 4180 KB Output is correct
14 Correct 3 ms 4180 KB Output is correct
15 Correct 2 ms 4180 KB Output is correct
16 Correct 2 ms 4228 KB Output is correct
17 Correct 2 ms 4180 KB Output is correct
18 Correct 2 ms 4228 KB Output is correct
19 Correct 2 ms 4180 KB Output is correct
20 Correct 3 ms 4180 KB Output is correct
21 Correct 2 ms 4180 KB Output is correct
22 Correct 2 ms 4180 KB Output is correct
23 Correct 3 ms 4240 KB Output is correct
24 Correct 3 ms 4180 KB Output is correct
25 Correct 3 ms 4308 KB Output is correct
26 Correct 3 ms 4308 KB Output is correct
27 Correct 6 ms 4360 KB Output is correct
28 Correct 5 ms 4308 KB Output is correct
29 Correct 4 ms 4180 KB Output is correct
30 Correct 3 ms 4236 KB Output is correct
31 Correct 4 ms 4180 KB Output is correct
32 Correct 7 ms 4240 KB Output is correct
33 Correct 104 ms 24168 KB Output is correct
34 Correct 117 ms 24188 KB Output is correct
35 Correct 249 ms 54416 KB Output is correct
36 Correct 252 ms 54412 KB Output is correct
37 Correct 167 ms 22356 KB Output is correct
38 Correct 168 ms 35136 KB Output is correct
39 Correct 103 ms 22092 KB Output is correct
40 Correct 237 ms 49552 KB Output is correct
41 Correct 125 ms 22112 KB Output is correct
42 Correct 146 ms 22204 KB Output is correct
43 Correct 209 ms 49928 KB Output is correct
44 Correct 220 ms 50092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4180 KB Output is correct
2 Correct 2 ms 4180 KB Output is correct
3 Correct 2 ms 4180 KB Output is correct
4 Correct 2 ms 4180 KB Output is correct
5 Correct 2 ms 4180 KB Output is correct
6 Correct 2 ms 4180 KB Output is correct
7 Correct 2 ms 4180 KB Output is correct
8 Correct 2 ms 4180 KB Output is correct
9 Correct 3 ms 4308 KB Output is correct
10 Correct 2 ms 4228 KB Output is correct
11 Correct 2 ms 4180 KB Output is correct
12 Correct 2 ms 4180 KB Output is correct
13 Correct 3 ms 4224 KB Output is correct
14 Correct 2 ms 4180 KB Output is correct
15 Correct 2 ms 4180 KB Output is correct
16 Correct 2 ms 4180 KB Output is correct
17 Correct 2 ms 4180 KB Output is correct
18 Correct 2 ms 4192 KB Output is correct
19 Correct 2 ms 4116 KB Output is correct
20 Correct 2 ms 4180 KB Output is correct
21 Correct 2 ms 4180 KB Output is correct
22 Correct 2 ms 4228 KB Output is correct
23 Correct 3 ms 4308 KB Output is correct
24 Correct 3 ms 4308 KB Output is correct
25 Correct 4 ms 4236 KB Output is correct
26 Correct 3 ms 4308 KB Output is correct
27 Correct 5 ms 4180 KB Output is correct
28 Correct 5 ms 4236 KB Output is correct
29 Correct 3 ms 4180 KB Output is correct
30 Correct 3 ms 4308 KB Output is correct
31 Correct 6 ms 4288 KB Output is correct
32 Correct 6 ms 4180 KB Output is correct
33 Correct 625 ms 48328 KB Output is correct
34 Correct 318 ms 57036 KB Output is correct
35 Correct 346 ms 48228 KB Output is correct
36 Correct 284 ms 52044 KB Output is correct
37 Correct 117 ms 24188 KB Output is correct
38 Correct 118 ms 24128 KB Output is correct
39 Correct 243 ms 54484 KB Output is correct
40 Correct 240 ms 54360 KB Output is correct
41 Correct 152 ms 22288 KB Output is correct
42 Correct 166 ms 35096 KB Output is correct
43 Correct 99 ms 22072 KB Output is correct
44 Correct 222 ms 49616 KB Output is correct
45 Correct 121 ms 22112 KB Output is correct
46 Correct 142 ms 22228 KB Output is correct
47 Correct 212 ms 49860 KB Output is correct
48 Correct 214 ms 49920 KB Output is correct
49 Correct 200 ms 27368 KB Output is correct
50 Correct 175 ms 27208 KB Output is correct
51 Correct 399 ms 56372 KB Output is correct
52 Correct 281 ms 55828 KB Output is correct
53 Correct 693 ms 25488 KB Output is correct
54 Correct 298 ms 39040 KB Output is correct
55 Correct 210 ms 23200 KB Output is correct
56 Correct 315 ms 51276 KB Output is correct
57 Correct 417 ms 23744 KB Output is correct
58 Correct 598 ms 24264 KB Output is correct
59 Correct 214 ms 49872 KB Output is correct