Submission #409064

# Submission time Handle Problem Language Result Execution time Memory
409064 2021-05-20T06:46:10 Z urd05 Horses (IOI15_horses) C++14
100 / 100
950 ms 45316 KB
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;

int n;
long long x[500000];
long long y[500000];
long long all=1;
const int mod=1e9+7;
const int sz=524288;
int seg[sz*2];
set<int> s;
typedef pair<long long,long long> P;

int sum(int l,int r,int node=1,int nodel=0,int noder=sz-1) {
    if (r<nodel||l>noder) {
        return 0;
    }
    if (l<=nodel&&noder<=r) {
        return seg[node];
    }
    int mid=(nodel+noder)/2;
    return max(sum(l,r,node*2,nodel,mid),sum(l,r,node*2+1,mid+1,noder));
}

void update(int i,int val) {
    i+=sz;
    seg[i]=val;
    while (i>1) {
        i/=2;
        seg[i]=max(seg[i*2],seg[i*2+1]);
    }
}

long long fastpow(long long a,long long b) {
    if (b==0) {
        return 1;
    }
    if (b%2==1) {
        return (fastpow(a,b-1)*a)%mod;
    }
    long long half=fastpow(a,b/2);
    return (half*half)%mod;
}

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];
        update(i,y[i]);
        all*=x[i];
        all%=mod;
        if (x[i]!=1) {
            s.insert(i);
        }
    }
    int pr=-1;
    P mx=P(0,1);
    long long gop=1;
    s.insert(0);
    auto iter=prev(s.end());
    pr=n;
    while (1) {
        int now=*iter;
        if (mx.first*gop<sum(now,pr-1)*mx.second) { // mx.first/mx.second > y[now]/gop
            mx=P(sum(now,pr-1),gop);
        }
        gop*=x[now];
        if (gop>mod||iter==s.begin()) {
            break;
        }
        iter--;
        pr=now;
    }
	long long val=mx.first*fastpow(mx.second,mod-2);
	val%=mod;
	return (all*val)%mod;
}

int updateX(int pos, int val) {
    all*=fastpow(x[pos],mod-2);
    all%=mod;
    all*=val;
    all%=mod;
    if (x[pos]!=1&&val==1) {
        s.erase(pos);
    }
    else if (x[pos]==1&&val!=1) {
        s.insert(pos);
    }
    x[pos]=val;
    P mx=P(0,1);
    long long gop=1;
    s.insert(0);
    auto iter=prev(s.end());
    int pr=n;
    while (1) {
        int now=*iter;
        if (mx.first*gop<sum(now,pr-1)*mx.second) { // mx.first/mx.second > y[now]/gop
            mx=P(sum(now,pr-1),gop);
        }
        gop*=x[now];
        if (gop>mod||iter==s.begin()) {
            break;
        }
        pr=now;
        iter--;
    }
	long long vl=mx.first*fastpow(mx.second,mod-2);
	vl%=mod;
	return (all*vl)%mod;
}

int updateY(int pos, int val) {
    update(pos,val);
    y[pos]=val;
    P mx=P(0,1);
    long long gop=1;
    s.insert(0);
    auto iter=prev(s.end());
    int pr=n;
    while (1) {
        int now=*iter;
        if (mx.first*gop<sum(now,pr-1)*mx.second) { // mx.first/mx.second > y[now]/gop
            mx=P(sum(now,pr-1),gop);
        }
        gop*=x[now];
        if (gop>mod||iter==s.begin()) {
            break;
        }
        pr=now;
        iter--;
    }
	long long vl=mx.first*fastpow(mx.second,mod-2);
	vl%=mod;
	return (all*vl)%mod;
}

Compilation message

horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:51:21: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   51 |         update(i,y[i]);
      |                  ~~~^
horses.cpp:78:18: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   78 |  return (all*val)%mod;
      |         ~~~~~~~~~^~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:112:17: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  112 |  return (all*vl)%mod;
      |         ~~~~~~~~^~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:137:17: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  137 |  return (all*vl)%mod;
      |         ~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 252 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
25 Correct 3 ms 444 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
27 Correct 7 ms 332 KB Output is correct
28 Correct 4 ms 440 KB Output is correct
29 Correct 2 ms 332 KB Output is correct
30 Correct 3 ms 460 KB Output is correct
31 Correct 5 ms 308 KB Output is correct
32 Correct 7 ms 416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 950 ms 40608 KB Output is correct
2 Correct 354 ms 40388 KB Output is correct
3 Correct 393 ms 40484 KB Output is correct
4 Correct 425 ms 40388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
25 Correct 3 ms 332 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
27 Correct 7 ms 332 KB Output is correct
28 Correct 4 ms 460 KB Output is correct
29 Correct 2 ms 332 KB Output is correct
30 Correct 2 ms 460 KB Output is correct
31 Correct 6 ms 332 KB Output is correct
32 Correct 7 ms 412 KB Output is correct
33 Correct 75 ms 20036 KB Output is correct
34 Correct 71 ms 19708 KB Output is correct
35 Correct 240 ms 43720 KB Output is correct
36 Correct 232 ms 43588 KB Output is correct
37 Correct 158 ms 18184 KB Output is correct
38 Correct 146 ms 31000 KB Output is correct
39 Correct 61 ms 17948 KB Output is correct
40 Correct 210 ms 43468 KB Output is correct
41 Correct 102 ms 17992 KB Output is correct
42 Correct 118 ms 18116 KB Output is correct
43 Correct 210 ms 43520 KB Output is correct
44 Correct 201 ms 43460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 424 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 360 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
25 Correct 4 ms 332 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
27 Correct 7 ms 332 KB Output is correct
28 Correct 4 ms 460 KB Output is correct
29 Correct 2 ms 332 KB Output is correct
30 Correct 2 ms 444 KB Output is correct
31 Correct 5 ms 332 KB Output is correct
32 Correct 7 ms 332 KB Output is correct
33 Correct 948 ms 44240 KB Output is correct
34 Correct 362 ms 45316 KB Output is correct
35 Correct 375 ms 43848 KB Output is correct
36 Correct 425 ms 44184 KB Output is correct
37 Correct 71 ms 19532 KB Output is correct
38 Correct 69 ms 19524 KB Output is correct
39 Correct 239 ms 43292 KB Output is correct
40 Correct 226 ms 43320 KB Output is correct
41 Correct 141 ms 18268 KB Output is correct
42 Correct 147 ms 30992 KB Output is correct
43 Correct 62 ms 17952 KB Output is correct
44 Correct 213 ms 43300 KB Output is correct
45 Correct 98 ms 18124 KB Output is correct
46 Correct 122 ms 18088 KB Output is correct
47 Correct 201 ms 43232 KB Output is correct
48 Correct 200 ms 43216 KB Output is correct
49 Correct 228 ms 21412 KB Output is correct
50 Correct 196 ms 21408 KB Output is correct
51 Correct 448 ms 44084 KB Output is correct
52 Correct 345 ms 44228 KB Output is correct
53 Correct 929 ms 21408 KB Output is correct
54 Correct 444 ms 34164 KB Output is correct
55 Correct 191 ms 19084 KB Output is correct
56 Correct 350 ms 44084 KB Output is correct
57 Correct 581 ms 19732 KB Output is correct
58 Correct 789 ms 20348 KB Output is correct
59 Correct 196 ms 43264 KB Output is correct