# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
304929 |
2020-09-22T08:17:01 Z |
jainbot27 |
Horses (IOI15_horses) |
C++17 |
|
996 ms |
79992 KB |
#include <bits/stdc++.h>
// #include "horses.h"
using namespace std;
#define f first
#define s second
#define pb push_back
#define ar array
#define all(x) x.begin(), x.end()
#define siz(x) (int)x.size()
#define FOR(x, y, z) for(int x = (y); x < (z); x++)
#define ROF(x, z, y) for(int x = (y-1); x >= (z); x--)
#define F0R(x, z) FOR(x, 0, z)
#define R0F(x, z) ROF(x, 0, z)
#define trav(x, y) for(auto&x:y)
using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
using ld = long double;
template<class T> inline bool ckmin(T&a, T b) {return b < a ? a = b, 1 : 0;}
template<class T> inline bool ckmax(T&a, T b) {return b > a ? a = b, 1 : 0;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const char nl = '\n';
const int mxN = 2e5 + 10;
const int MOD = 1e9 + 7;
const long long infLL = 1e18;
// modulo class
int add(int x, int y){ x += y; while(x >= MOD) x -= MOD; while(x < 0) x += MOD; return x; } void ad(int &x, int y) {x = add(x, y);}
int sub(int x, int y){ x -= y; while(x >= MOD) x -= MOD; while(x < 0) x += MOD; return x; } void sb(int &x, int y) {x = sub(x, y);}
int mul(int x, int y){ return ((int64_t)x * (int64_t)y) % MOD; } void ml(int &x, int y) {x = mul(x, y);}
int binpow(int x, int y){ int z = 1; while(y > 0) { if(y % 2 == 1) z = mul(z, x); x = mul(x, x); y /= 2; } return z; }
int inv(int x){ return binpow(x, MOD - 2); }
int divide(int x, int y){ return mul(x, inv(y)); }
template<class T, int X> struct segtree{ // comb(ID,b) = b
T ID = 0;
T comb(T a, T b) {
if(X == 1)
return a+b;
else if(X==0)
return mul(a, b);
else
return max(a, b);
}
int n; vector<T> seg;
void init(int _n) { n = _n; if(X!=0)seg.assign(2*n,ID); else seg.assign(2*n, 1); }
void pull(int p) { seg[p] = comb(seg[2*p],seg[2*p+1]); }
void update(T val, int p) {
p++;// set val at position p
seg[p += n] = val; for (p /= 2; p; p /= 2) pull(p); }
T query(int l, int r) { // sum on interval [l, r]
if(r == -499) {
return (X?0:1);
}
l++; r++;
r--;
T ra = (X?ID:1), rb = (X?ID:1);
for (l += n, r += n+1; l < r; l /= 2, r /= 2) {
if (l&1) ra = comb(ra,seg[l++]);
if (r&1) rb = comb(seg[--r],rb);
}
return comb(ra,rb);
}
};
int n; vi x, y, l, r; vector<ld> lg; segtree<ld, 1> lgs; segtree<int, 0> act; segtree<int, 2> ys;
set<int> vals;
int getANS(){
// cout << "BRUHMOMEN" << endl;
auto it = vals.rbegin();
int i = 0;
ld best = 0; int pos = 0;
while(it!=vals.rend() && i < 35){
int _x = *it;
if(_x == -500) {
_x=n;
if(r[_x] == -1) {
i++; it++;
break;
}
}
if(ckmax(best, lgs.query(0, *it+1) + log(ys.query(l[_x], r[_x]+1)))){
pos = *it;
}
i++; it++;
}
i = pos;
if(pos == -500) i=n;
return mul(act.query(0, pos+1), ys.query(l[i], r[i]+1));
}
int init(int _n, int _x[], int _y[]){
n = _n; x.resize(n); y.resize(n); lg.resize(n); l.resize(n+1); r.resize(n+1);
lgs.init(n+1); act.init(n+1); ys.init(n+1);
F0R(i, n) x[i] = _x[i];
F0R(i, n) y[i] = _y[i];
F0R(i, n){
lg[i] = log(x[i]);
}
F0R(i, n){
lgs.update(lg[i], i);
ys.update(y[i], i);
act.update(x[i], i);
}
int j = n;
R0F(i, n){
if(x[i] == 1){
}
else{
r[i] = j-1;
l[i] = i;
j = i;
vals.insert(i);
}
}
l[n] = 0; r[n] = -1;
if(j) {
r[n] = j - 1;
}
vals.insert(-500);
int res = getANS();
return res;
}
int updateX(int pos, int val){
if(x[pos] == val) return getANS();
if(val == 1){
auto it = vals.find(pos);
int en = (it==prev(vals.end())?n:*(next(it)))-1;
if(*prev(it) != -500)
r[*prev(it)] = en;
else
r[n] = en;
vals.erase(it);
}
else if(x[pos] == 1){
vals.insert(pos);
auto it = vals.find(pos);
if(*prev(it) != -500)
r[*prev(it)] = pos - 1;
else
r[n] = pos - 1;
int en = (it==prev(vals.end())?n:*(next(it)))-1;
l[pos] = pos; r[pos] = en;
cout << endl;
}
act.update(val, pos);
lgs.update(log(val), pos);
x[pos]=val;
return getANS();
}
int updateY(int pos, int val){
ys.update(val, pos);
return getANS();
}
// int main(){
// int _n = 3;
// int _x[] = {2, 1, 3};
// int _y[] = {3, 2, 1};
// cout << init(_n, _x, _y);
// }
Compilation message
horses.cpp: In function 'int mul(int, int)':
horses.cpp:37:57: warning: conversion from 'int64_t' {aka 'long int'} to 'int' may change value [-Wconversion]
37 | int mul(int x, int y){ return ((int64_t)x * (int64_t)y) % MOD; } void ml(int &x, int y) {x = mul(x, y);}
| ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
256 KB |
Output is correct |
7 |
Correct |
0 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
0 ms |
256 KB |
Output is correct |
10 |
Correct |
0 ms |
256 KB |
Output is correct |
11 |
Correct |
0 ms |
256 KB |
Output is correct |
12 |
Correct |
0 ms |
256 KB |
Output is correct |
13 |
Correct |
0 ms |
256 KB |
Output is correct |
14 |
Correct |
0 ms |
256 KB |
Output is correct |
15 |
Correct |
0 ms |
256 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
256 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Correct |
0 ms |
256 KB |
Output is correct |
20 |
Correct |
1 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
256 KB |
Output is correct |
7 |
Correct |
0 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
0 ms |
256 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
256 KB |
Output is correct |
12 |
Correct |
0 ms |
256 KB |
Output is correct |
13 |
Correct |
0 ms |
256 KB |
Output is correct |
14 |
Correct |
0 ms |
256 KB |
Output is correct |
15 |
Correct |
0 ms |
256 KB |
Output is correct |
16 |
Correct |
0 ms |
256 KB |
Output is correct |
17 |
Correct |
0 ms |
256 KB |
Output is correct |
18 |
Correct |
0 ms |
256 KB |
Output is correct |
19 |
Correct |
0 ms |
256 KB |
Output is correct |
20 |
Correct |
0 ms |
256 KB |
Output is correct |
21 |
Correct |
1 ms |
256 KB |
Output is correct |
22 |
Correct |
0 ms |
256 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
512 KB |
Output is correct |
26 |
Correct |
5 ms |
512 KB |
Output is correct |
27 |
Correct |
4 ms |
384 KB |
Output is correct |
28 |
Correct |
6 ms |
512 KB |
Output is correct |
29 |
Correct |
2 ms |
384 KB |
Output is correct |
30 |
Correct |
4 ms |
512 KB |
Output is correct |
31 |
Correct |
2 ms |
384 KB |
Output is correct |
32 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
814 ms |
68036 KB |
Output is correct |
2 |
Correct |
994 ms |
68088 KB |
Output is correct |
3 |
Correct |
856 ms |
68088 KB |
Output is correct |
4 |
Correct |
986 ms |
67960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
256 KB |
Output is correct |
7 |
Correct |
0 ms |
256 KB |
Output is correct |
8 |
Correct |
0 ms |
256 KB |
Output is correct |
9 |
Correct |
0 ms |
256 KB |
Output is correct |
10 |
Correct |
0 ms |
276 KB |
Output is correct |
11 |
Correct |
0 ms |
256 KB |
Output is correct |
12 |
Correct |
0 ms |
256 KB |
Output is correct |
13 |
Correct |
1 ms |
256 KB |
Output is correct |
14 |
Correct |
0 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
256 KB |
Output is correct |
16 |
Correct |
0 ms |
256 KB |
Output is correct |
17 |
Correct |
0 ms |
256 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
256 KB |
Output is correct |
20 |
Correct |
1 ms |
256 KB |
Output is correct |
21 |
Correct |
0 ms |
256 KB |
Output is correct |
22 |
Correct |
1 ms |
256 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
640 KB |
Output is correct |
26 |
Correct |
5 ms |
512 KB |
Output is correct |
27 |
Correct |
4 ms |
384 KB |
Output is correct |
28 |
Correct |
6 ms |
512 KB |
Output is correct |
29 |
Correct |
2 ms |
384 KB |
Output is correct |
30 |
Correct |
4 ms |
512 KB |
Output is correct |
31 |
Correct |
2 ms |
384 KB |
Output is correct |
32 |
Correct |
4 ms |
384 KB |
Output is correct |
33 |
Correct |
305 ms |
43640 KB |
Output is correct |
34 |
Correct |
305 ms |
43640 KB |
Output is correct |
35 |
Correct |
460 ms |
67204 KB |
Output is correct |
36 |
Correct |
463 ms |
67064 KB |
Output is correct |
37 |
Correct |
284 ms |
43640 KB |
Output is correct |
38 |
Correct |
371 ms |
55500 KB |
Output is correct |
39 |
Correct |
244 ms |
43384 KB |
Output is correct |
40 |
Correct |
440 ms |
67000 KB |
Output is correct |
41 |
Correct |
255 ms |
43456 KB |
Output is correct |
42 |
Correct |
272 ms |
43608 KB |
Output is correct |
43 |
Correct |
388 ms |
66880 KB |
Output is correct |
44 |
Correct |
397 ms |
67064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
0 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
0 ms |
256 KB |
Output is correct |
12 |
Correct |
1 ms |
256 KB |
Output is correct |
13 |
Correct |
0 ms |
256 KB |
Output is correct |
14 |
Correct |
0 ms |
256 KB |
Output is correct |
15 |
Correct |
0 ms |
256 KB |
Output is correct |
16 |
Correct |
1 ms |
256 KB |
Output is correct |
17 |
Correct |
1 ms |
256 KB |
Output is correct |
18 |
Correct |
0 ms |
256 KB |
Output is correct |
19 |
Correct |
1 ms |
256 KB |
Output is correct |
20 |
Correct |
0 ms |
256 KB |
Output is correct |
21 |
Correct |
1 ms |
256 KB |
Output is correct |
22 |
Correct |
1 ms |
256 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
7 ms |
512 KB |
Output is correct |
26 |
Correct |
5 ms |
512 KB |
Output is correct |
27 |
Correct |
4 ms |
384 KB |
Output is correct |
28 |
Correct |
6 ms |
512 KB |
Output is correct |
29 |
Correct |
2 ms |
384 KB |
Output is correct |
30 |
Correct |
4 ms |
512 KB |
Output is correct |
31 |
Correct |
2 ms |
384 KB |
Output is correct |
32 |
Correct |
4 ms |
384 KB |
Output is correct |
33 |
Correct |
807 ms |
68028 KB |
Output is correct |
34 |
Correct |
983 ms |
67960 KB |
Output is correct |
35 |
Correct |
859 ms |
67832 KB |
Output is correct |
36 |
Correct |
991 ms |
68052 KB |
Output is correct |
37 |
Correct |
314 ms |
47608 KB |
Output is correct |
38 |
Correct |
305 ms |
47608 KB |
Output is correct |
39 |
Correct |
467 ms |
77944 KB |
Output is correct |
40 |
Correct |
464 ms |
77816 KB |
Output is correct |
41 |
Correct |
285 ms |
45816 KB |
Output is correct |
42 |
Correct |
370 ms |
58496 KB |
Output is correct |
43 |
Correct |
253 ms |
45512 KB |
Output is correct |
44 |
Correct |
446 ms |
72952 KB |
Output is correct |
45 |
Correct |
256 ms |
45560 KB |
Output is correct |
46 |
Correct |
277 ms |
45688 KB |
Output is correct |
47 |
Correct |
393 ms |
73336 KB |
Output is correct |
48 |
Correct |
397 ms |
73336 KB |
Output is correct |
49 |
Correct |
903 ms |
50676 KB |
Output is correct |
50 |
Correct |
883 ms |
50808 KB |
Output is correct |
51 |
Correct |
971 ms |
79992 KB |
Output is correct |
52 |
Correct |
983 ms |
79224 KB |
Output is correct |
53 |
Correct |
744 ms |
48888 KB |
Output is correct |
54 |
Correct |
996 ms |
62512 KB |
Output is correct |
55 |
Correct |
382 ms |
46584 KB |
Output is correct |
56 |
Correct |
893 ms |
74756 KB |
Output is correct |
57 |
Correct |
484 ms |
47224 KB |
Output is correct |
58 |
Correct |
679 ms |
47864 KB |
Output is correct |
59 |
Correct |
391 ms |
73244 KB |
Output is correct |