Submission #442355

# Submission time Handle Problem Language Result Execution time Memory
442355 2021-07-07T13:57:16 Z FEDIKUS Horses (IOI15_horses) C++17
100 / 100
1074 ms 32196 KB
#include "horses.h"

#include<bits/stdc++.h>
#define mp make_pair

using namespace std;

typedef long long ll;

const int maxn=5e5+10;
const int mod=1e9+7;
int n;
int bseg[4*maxn];
int y[maxn];
pair<bool,int> pseg[4*maxn];

pair<bool,int> comb(pair<bool,int> a,pair<bool,int> b){
    if(a.first || b.first){
        return mp(true,ll(a.second)*ll(b.second)%mod);
    }
    if(ll(a.second)*ll(b.second)>=mod){
        return mp(true,ll(a.second)*ll(b.second)%mod);
    }
    return mp(false,ll(a.second)*ll(b.second));
}

void buildp(int *x,int ind=1,int l=0,int r=n-1){
    if(l==r){
        pseg[ind]={false,x[l]};
        return;
    }
    int mid=l+(r-l)/2;
    buildp(x,2*ind,l,mid);
    buildp(x,2*ind+1,mid+1,r);
    pseg[ind]=comb(pseg[2*ind],pseg[2*ind+1]);
}

void updatep(int t,int v,int ind=1,int l=0,int r=n-1){
    if(l==r){
        pseg[ind]={false,v};
        return;
    }
    int mid=l+(r-l)/2;
    if(t<=mid) updatep(t,v,2*ind,l,mid);
    if(t>mid) updatep(t,v,2*ind+1,mid+1,r);
    pseg[ind]=comb(pseg[2*ind],pseg[2*ind+1]);
}

pair<bool,int> queryp(int tl,int tr,int ind=1,int l=0,int r=n-1){
    if(tl<=l && r<=tr) return pseg[ind];
    int mid=l+(r-l)/2;
    pair<bool,int> ret={false,1};
    if(tl<=mid) ret=comb(ret,queryp(tl,tr,2*ind,l,mid));
    if(tr>mid) ret=comb(ret,queryp(tl,tr,2*ind+1,mid+1,r));
    return ret;
}

int comp(int a,int b){
    if(a>b) swap(a,b);
    pair<bool,int> raz=queryp(a+1,b);
    raz=comb(raz,mp(false,y[b]));
    if(raz.first) return b;
    if(raz.second>y[a]) return b;
    else return a;
}

void buildb(int ind=1,int l=0,int r=n-1){
    if(l==r){
        bseg[ind]=l;
        return;
    }
    int mid=l+(r-l)/2;
    buildb(2*ind,l,mid);
    buildb(2*ind+1,mid+1,r);
    bseg[ind]=comp(bseg[2*ind],bseg[2*ind+1]);
}

void updateb(int t,int ind=1,int l=0,int r=n-1){
    if(l==r) return;
    int mid=l+(r-l)/2;
    if(t<=mid) updateb(t,2*ind,l,mid);
    if(t>mid) updateb(t,2*ind+1,mid+1,r);
    bseg[ind]=comp(bseg[2*ind],bseg[2*ind+1]);
}

int init(int N, int X[], int Y[]) {
	n=N;
	for(int i=0;i<n;i++) y[i]=Y[i];
	buildp(X);
	buildb();
	return comb(queryp(0,bseg[1]),mp(false,y[bseg[1]])).second;
}

int updateX(int pos, int val) {
    updatep(pos,val);
    updateb(pos);
	return comb(queryp(0,bseg[1]),mp(false,y[bseg[1]])).second;
}

int updateY(int pos, int val) {
    y[pos]=val;
    updateb(pos);
	return comb(queryp(0,bseg[1]),mp(false,y[bseg[1]])).second;
}
/*
3
2 1 3
3 4 1
1
2 1 2
*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
25 Correct 2 ms 312 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
27 Correct 3 ms 332 KB Output is correct
28 Correct 2 ms 332 KB Output is correct
29 Correct 2 ms 332 KB Output is correct
30 Correct 2 ms 332 KB Output is correct
31 Correct 2 ms 332 KB Output is correct
32 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 601 ms 19388 KB Output is correct
2 Correct 570 ms 32192 KB Output is correct
3 Correct 705 ms 23360 KB Output is correct
4 Correct 672 ms 27004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 3 ms 332 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
27 Correct 2 ms 332 KB Output is correct
28 Correct 2 ms 332 KB Output is correct
29 Correct 2 ms 332 KB Output is correct
30 Correct 2 ms 332 KB Output is correct
31 Correct 2 ms 332 KB Output is correct
32 Correct 2 ms 332 KB Output is correct
33 Correct 242 ms 22480 KB Output is correct
34 Correct 246 ms 22468 KB Output is correct
35 Correct 234 ms 29476 KB Output is correct
36 Correct 213 ms 29380 KB Output is correct
37 Correct 246 ms 20712 KB Output is correct
38 Correct 195 ms 21588 KB Output is correct
39 Correct 216 ms 20556 KB Output is correct
40 Correct 211 ms 24516 KB Output is correct
41 Correct 204 ms 20548 KB Output is correct
42 Correct 216 ms 20568 KB Output is correct
43 Correct 170 ms 24972 KB Output is correct
44 Correct 162 ms 24860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 2 ms 312 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
27 Correct 3 ms 332 KB Output is correct
28 Correct 2 ms 332 KB Output is correct
29 Correct 2 ms 332 KB Output is correct
30 Correct 2 ms 332 KB Output is correct
31 Correct 2 ms 332 KB Output is correct
32 Correct 3 ms 332 KB Output is correct
33 Correct 604 ms 23292 KB Output is correct
34 Correct 568 ms 32196 KB Output is correct
35 Correct 698 ms 23280 KB Output is correct
36 Correct 662 ms 27204 KB Output is correct
37 Correct 245 ms 22468 KB Output is correct
38 Correct 230 ms 22400 KB Output is correct
39 Correct 238 ms 29380 KB Output is correct
40 Correct 209 ms 29556 KB Output is correct
41 Correct 235 ms 20600 KB Output is correct
42 Correct 191 ms 21596 KB Output is correct
43 Correct 216 ms 20548 KB Output is correct
44 Correct 216 ms 24504 KB Output is correct
45 Correct 204 ms 20572 KB Output is correct
46 Correct 220 ms 20676 KB Output is correct
47 Correct 174 ms 24804 KB Output is correct
48 Correct 162 ms 24792 KB Output is correct
49 Correct 1074 ms 24484 KB Output is correct
50 Correct 906 ms 24516 KB Output is correct
51 Correct 698 ms 31288 KB Output is correct
52 Correct 460 ms 30780 KB Output is correct
53 Correct 1058 ms 22904 KB Output is correct
54 Correct 619 ms 23292 KB Output is correct
55 Correct 841 ms 21572 KB Output is correct
56 Correct 691 ms 26300 KB Output is correct
57 Correct 708 ms 22184 KB Output is correct
58 Correct 831 ms 22920 KB Output is correct
59 Correct 163 ms 24772 KB Output is correct