답안 #432492

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
432492 2021-06-18T10:40:42 Z balbit 말 (IOI15_horses) C++14
100 / 100
443 ms 60880 KB
#include "horses.h"

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pii pair<int, int>
#define f first
#define s second

#ifdef BALBIT
#define bug(...) cerr<<"#"<<__LINE__<<": "<<#__VA_ARGS__<<"- ", _do(__VA_ARGS__)
template<typename T> void _do( T && x) {cerr<<x<<endl;}
template<typename T, typename ...S> void _do( T && x, S && ...y) {cerr<<x<<", "; _do(y...);}
#else
#define bug(...)
#endif // BALBIT


#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int )((x).size())
#define pb push_back

#define REP(i,n) for (int i = 0; i<n; ++i)
#define REP1(i,n) for (int i = 1; i<=n; ++i)

#define MX(a,b) a = max(a,b)
#define MN(a,b) a = min(a,b)

//signed main(){bug(1,2);}

const int maxn = 5e5+5;
const int mod = 1e9+7;

ll X[maxn], Y[maxn], s[maxn], seg[maxn*2];
int n;
ll inv(ll b) {
    return b == 1? 1 : inv(mod%b) * (mod - mod / b) % mod;
}

set<int> notone;
int QU(int e) {
    ll re = 1;
    for (++e; e>0; e-=e&-e) {
        re = re * s[e] % mod;
    }
    return re;
}

void MO(int e, ll v) {
    for (++e; e<maxn; e+=e&-e) {
        s[e] *= v; s[e] %= mod;
    }
}

ll cap = 1e9+10;

void modify(int p, int v) {
    p+=maxn;
//    bug(p,v);
    for (seg[p] = v; p>1; p>>=1) {
        seg[p>>1] = max(seg[p], seg[p^1]);
//        bug(seg[p>>1]);
    }
}

ll query(int l, int r) {
    ll re = 1;
    for (l+=maxn, r+=maxn; l<r; l>>=1, r>>=1) {
        if (l & 1) MX(re, seg[l++]);
        if (r & 1) MX(re, seg[--r]);
    }
    return re;
}

int get(){
    auto sit = prev(notone.end());
    ll bon = 1;
    ll nowbig = 0;
    int prv = n;
    while (1) {
        int i = *sit;
        MX(nowbig, query(i, prv)); // [,)
        bug(i, prv, query(i,prv));
        prv = i;
        nowbig *= X[i];
        bug(i, nowbig);
        if (sit == notone.begin() || nowbig > cap) break;
        --sit;
    }
    nowbig %= mod;
    return nowbig * QU(prv-1) % mod;
}

bool good(int i) {
    return i == 0 || X[i] != 1;
}

int init(int _n, int _X[], int _Y[]) {
    fill(s, s+maxn, 1);
    fill(seg, seg+maxn*2, 0);
    n = _n;
    REP(i,_n) {
        X[i] = _X[i]; Y[i] = _Y[i];
        MO(i, X[i]);
        modify(i, Y[i]);
        if (good(i)) notone.insert(i);
    }
	return get();
}

int updateX(int i, int val) {
    if (good(i)) notone.erase(i);
    MO(i, inv(X[i]));
    X[i] = val;
    if (good(i)) notone.insert(i);
    MO(i, (X[i]));
	return get();
}

int updateY(int pos, int val) {
    modify(pos, val);
	return get();
}

//signed main(){
//    bug(inv(2));
//}

Compilation message

horses.cpp: In function 'int QU(int)':
horses.cpp:47:12: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   47 |     return re;
      |            ^~
horses.cpp: In function 'int get()':
horses.cpp:92:31: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   92 |     return nowbig * QU(prv-1) % mod;
      |            ~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp:78:8: warning: unused variable 'bon' [-Wunused-variable]
   78 |     ll bon = 1;
      |        ^~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:106:22: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  106 |         modify(i, Y[i]);
      |                   ~~~^
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 11980 KB Output is correct
2 Correct 7 ms 11980 KB Output is correct
3 Correct 6 ms 11980 KB Output is correct
4 Correct 7 ms 11980 KB Output is correct
5 Correct 7 ms 11980 KB Output is correct
6 Correct 8 ms 11980 KB Output is correct
7 Correct 7 ms 11976 KB Output is correct
8 Correct 7 ms 11932 KB Output is correct
9 Correct 8 ms 11980 KB Output is correct
10 Correct 7 ms 11976 KB Output is correct
11 Correct 6 ms 11932 KB Output is correct
12 Correct 6 ms 11980 KB Output is correct
13 Correct 7 ms 11980 KB Output is correct
14 Correct 7 ms 11980 KB Output is correct
15 Correct 7 ms 11980 KB Output is correct
16 Correct 7 ms 11980 KB Output is correct
17 Correct 6 ms 11980 KB Output is correct
18 Correct 8 ms 11948 KB Output is correct
19 Correct 7 ms 11980 KB Output is correct
20 Correct 7 ms 11980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 11980 KB Output is correct
2 Correct 7 ms 11980 KB Output is correct
3 Correct 8 ms 11980 KB Output is correct
4 Correct 7 ms 12016 KB Output is correct
5 Correct 7 ms 11980 KB Output is correct
6 Correct 7 ms 11980 KB Output is correct
7 Correct 7 ms 11980 KB Output is correct
8 Correct 7 ms 11980 KB Output is correct
9 Correct 7 ms 11980 KB Output is correct
10 Correct 7 ms 11980 KB Output is correct
11 Correct 7 ms 11980 KB Output is correct
12 Correct 7 ms 11980 KB Output is correct
13 Correct 8 ms 11980 KB Output is correct
14 Correct 8 ms 11980 KB Output is correct
15 Correct 7 ms 11980 KB Output is correct
16 Correct 7 ms 11980 KB Output is correct
17 Correct 7 ms 11980 KB Output is correct
18 Correct 7 ms 11980 KB Output is correct
19 Correct 7 ms 11980 KB Output is correct
20 Correct 7 ms 11980 KB Output is correct
21 Correct 7 ms 12000 KB Output is correct
22 Correct 8 ms 11980 KB Output is correct
23 Correct 7 ms 12068 KB Output is correct
24 Correct 7 ms 12108 KB Output is correct
25 Correct 8 ms 12108 KB Output is correct
26 Correct 8 ms 12088 KB Output is correct
27 Correct 8 ms 12072 KB Output is correct
28 Correct 8 ms 12108 KB Output is correct
29 Correct 7 ms 11980 KB Output is correct
30 Correct 8 ms 12092 KB Output is correct
31 Correct 7 ms 11980 KB Output is correct
32 Correct 8 ms 11980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 248 ms 48132 KB Output is correct
2 Correct 374 ms 60796 KB Output is correct
3 Correct 345 ms 51908 KB Output is correct
4 Correct 443 ms 56012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 11980 KB Output is correct
2 Correct 7 ms 11980 KB Output is correct
3 Correct 8 ms 12040 KB Output is correct
4 Correct 8 ms 11980 KB Output is correct
5 Correct 8 ms 12048 KB Output is correct
6 Correct 7 ms 11976 KB Output is correct
7 Correct 7 ms 11992 KB Output is correct
8 Correct 8 ms 11980 KB Output is correct
9 Correct 7 ms 11980 KB Output is correct
10 Correct 7 ms 12032 KB Output is correct
11 Correct 7 ms 11980 KB Output is correct
12 Correct 7 ms 12016 KB Output is correct
13 Correct 7 ms 11980 KB Output is correct
14 Correct 6 ms 11980 KB Output is correct
15 Correct 7 ms 11980 KB Output is correct
16 Correct 8 ms 12008 KB Output is correct
17 Correct 7 ms 11980 KB Output is correct
18 Correct 7 ms 11980 KB Output is correct
19 Correct 7 ms 11980 KB Output is correct
20 Correct 7 ms 11988 KB Output is correct
21 Correct 7 ms 11956 KB Output is correct
22 Correct 6 ms 11980 KB Output is correct
23 Correct 7 ms 12108 KB Output is correct
24 Correct 7 ms 12108 KB Output is correct
25 Correct 7 ms 12108 KB Output is correct
26 Correct 7 ms 12108 KB Output is correct
27 Correct 7 ms 11980 KB Output is correct
28 Correct 7 ms 12108 KB Output is correct
29 Correct 7 ms 12108 KB Output is correct
30 Correct 8 ms 12108 KB Output is correct
31 Correct 8 ms 11980 KB Output is correct
32 Correct 9 ms 11980 KB Output is correct
33 Correct 71 ms 28000 KB Output is correct
34 Correct 69 ms 27900 KB Output is correct
35 Correct 237 ms 58208 KB Output is correct
36 Correct 249 ms 58164 KB Output is correct
37 Correct 66 ms 26052 KB Output is correct
38 Correct 131 ms 38732 KB Output is correct
39 Correct 57 ms 25724 KB Output is correct
40 Correct 266 ms 53148 KB Output is correct
41 Correct 57 ms 25796 KB Output is correct
42 Correct 59 ms 25852 KB Output is correct
43 Correct 218 ms 53640 KB Output is correct
44 Correct 208 ms 53632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 11980 KB Output is correct
2 Correct 7 ms 11948 KB Output is correct
3 Correct 7 ms 12036 KB Output is correct
4 Correct 7 ms 11980 KB Output is correct
5 Correct 7 ms 11980 KB Output is correct
6 Correct 7 ms 11980 KB Output is correct
7 Correct 6 ms 11980 KB Output is correct
8 Correct 8 ms 11980 KB Output is correct
9 Correct 6 ms 11980 KB Output is correct
10 Correct 7 ms 11980 KB Output is correct
11 Correct 7 ms 11980 KB Output is correct
12 Correct 7 ms 11980 KB Output is correct
13 Correct 6 ms 11980 KB Output is correct
14 Correct 7 ms 11944 KB Output is correct
15 Correct 7 ms 11996 KB Output is correct
16 Correct 7 ms 11964 KB Output is correct
17 Correct 7 ms 11992 KB Output is correct
18 Correct 8 ms 11980 KB Output is correct
19 Correct 7 ms 11980 KB Output is correct
20 Correct 7 ms 11980 KB Output is correct
21 Correct 6 ms 11980 KB Output is correct
22 Correct 7 ms 11980 KB Output is correct
23 Correct 7 ms 12108 KB Output is correct
24 Correct 8 ms 12044 KB Output is correct
25 Correct 7 ms 12108 KB Output is correct
26 Correct 8 ms 12108 KB Output is correct
27 Correct 8 ms 12088 KB Output is correct
28 Correct 7 ms 12108 KB Output is correct
29 Correct 7 ms 11980 KB Output is correct
30 Correct 8 ms 12108 KB Output is correct
31 Correct 8 ms 12068 KB Output is correct
32 Correct 7 ms 11980 KB Output is correct
33 Correct 245 ms 52056 KB Output is correct
34 Correct 370 ms 60880 KB Output is correct
35 Correct 344 ms 51948 KB Output is correct
36 Correct 424 ms 55804 KB Output is correct
37 Correct 69 ms 27844 KB Output is correct
38 Correct 69 ms 27908 KB Output is correct
39 Correct 244 ms 58220 KB Output is correct
40 Correct 238 ms 58124 KB Output is correct
41 Correct 67 ms 26068 KB Output is correct
42 Correct 148 ms 38816 KB Output is correct
43 Correct 71 ms 25796 KB Output is correct
44 Correct 225 ms 53144 KB Output is correct
45 Correct 57 ms 25988 KB Output is correct
46 Correct 58 ms 25920 KB Output is correct
47 Correct 230 ms 53576 KB Output is correct
48 Correct 220 ms 53544 KB Output is correct
49 Correct 126 ms 30944 KB Output is correct
50 Correct 145 ms 30980 KB Output is correct
51 Correct 290 ms 60044 KB Output is correct
52 Correct 288 ms 59740 KB Output is correct
53 Correct 164 ms 29144 KB Output is correct
54 Correct 184 ms 42660 KB Output is correct
55 Correct 121 ms 26868 KB Output is correct
56 Correct 308 ms 54960 KB Output is correct
57 Correct 98 ms 27460 KB Output is correct
58 Correct 121 ms 27972 KB Output is correct
59 Correct 216 ms 53532 KB Output is correct