답안 #414529

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
414529 2021-05-30T15:16:07 Z TLP39 말 (IOI15_horses) C++14
100 / 100
847 ms 52404 KB
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,bool> lb;

int n;
const ll big=1000000007;
lb seg_x[2000040];
int seg_m[2000040];
ll y[500010];
int pos[500010];
int inte[2000040][2];

void build_x(int X[],int v,int st,int ed)
{
    inte[v][0]=st;
    inte[v][1]=ed;
    if(st==ed)
    {
        pos[st]=v;
        seg_x[v]={((ll)X[st])%big,((ll)X[st])>=big};
        return;
    }
    int mid=(st+ed)>>1;
    build_x(X,2*v,st,mid);
    build_x(X,2*v+1,mid+1,ed);
    ll temp=seg_x[2*v].first*seg_x[2*v+1].first;
    seg_x[v]={temp%big,(temp>=big || seg_x[2*v].second || seg_x[2*v+1].second)};
}

lb ti(lb a,lb b)
{
    ll temp=a.first*b.first;
    return {(temp%big),temp>=big || a.second || b.second};
}

lb prod(int st,int ed,int v)
{
    if(st==inte[v][0] && ed==inte[v][1]) return seg_x[v];
    int mid=(inte[v][0]+inte[v][1])>>1;
    if(ed<=mid) return prod(st,ed,2*v);
    if(st>mid) return prod(st,ed,2*v+1);
    return ti(prod(st,mid,2*v),prod(mid+1,ed,2*v+1));
}

void build_m(int v,int st,int ed)
{
    if(st==ed)
    {
        seg_m[v]=st;
        return;
    }
    int mid=(st+ed)>>1;
    build_m(2*v,st,mid);
    build_m(2*v+1,mid+1,ed);
    int a=seg_m[2*v],b=seg_m[2*v+1];
    lb temp=prod(a+1,b,1);
    if(temp.second || temp.first*y[b]>=y[a]) seg_m[v]=b;
    else seg_m[v]=a;
}

int init(int N, int X[], int Y[]) {
    n=N;
    for(int i=0;i<n;i++) y[i]=Y[i];
	build_x(X,1,0,n-1);
	build_m(1,0,n-1);
	int temp=seg_m[1];
	return (int)((prod(0,temp,1).first*y[temp])%big);
}

void change(int p)
{
    int v=pos[p];
    v>>=1;
    int a,b;
    lb temp;
    while(v)
    {
        a=seg_m[2*v];
        b=seg_m[2*v+1];
        temp=prod(a+1,b,1);
        if(temp.second || temp.first*y[b]>=y[a]) seg_m[v]=b;
        else seg_m[v]=a;
        v>>=1;
    }
}

int updateX(int p, int val) {
    int v=pos[p];
    seg_x[v]={((ll)val)%big,((ll)val)>=big};
    v>>=1;
    ll temp;
    while(v)
    {
        temp=seg_x[2*v].first*seg_x[2*v+1].first;
        seg_x[v]={temp%big,(temp>=big || seg_x[2*v].second || seg_x[2*v+1].second)};
        v>>=1;
    }
    change(p);
	int temp2=seg_m[1];
	return (int)((prod(0,temp2,1).first*y[temp2])%big);
}

int updateY(int p, int val) {
    y[p]=val;
    change(p);
	int temp2=seg_m[1];
	return (int)((prod(0,temp2,1).first*y[temp2])%big);
}
# 결과 실행 시간 메모리 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 304 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 304 KB Output is correct
11 Correct 1 ms 304 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 304 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 304 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 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 304 KB Output is correct
7 Correct 1 ms 300 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 304 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 300 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 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 1 ms 332 KB Output is correct
30 Correct 1 ms 444 KB Output is correct
31 Correct 2 ms 332 KB Output is correct
32 Correct 2 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 291 ms 43588 KB Output is correct
2 Correct 331 ms 52308 KB Output is correct
3 Correct 453 ms 43588 KB Output is correct
4 Correct 421 ms 47428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 284 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 304 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 280 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 1 ms 300 KB Output is correct
12 Correct 1 ms 280 KB Output is correct
13 Correct 1 ms 300 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 308 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 304 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 3 ms 332 KB Output is correct
24 Correct 3 ms 332 KB Output is correct
25 Correct 2 ms 312 KB Output is correct
26 Correct 2 ms 420 KB Output is correct
27 Correct 2 ms 332 KB Output is correct
28 Correct 2 ms 332 KB Output is correct
29 Correct 1 ms 308 KB Output is correct
30 Correct 2 ms 332 KB Output is correct
31 Correct 2 ms 308 KB Output is correct
32 Correct 2 ms 312 KB Output is correct
33 Correct 164 ms 42804 KB Output is correct
34 Correct 147 ms 42908 KB Output is correct
35 Correct 136 ms 49736 KB Output is correct
36 Correct 131 ms 49680 KB Output is correct
37 Correct 111 ms 41008 KB Output is correct
38 Correct 100 ms 41924 KB Output is correct
39 Correct 91 ms 40904 KB Output is correct
40 Correct 96 ms 44832 KB Output is correct
41 Correct 105 ms 40944 KB Output is correct
42 Correct 87 ms 40960 KB Output is correct
43 Correct 92 ms 45180 KB Output is correct
44 Correct 93 ms 45140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 280 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 304 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 324 KB Output is correct
9 Correct 1 ms 284 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 460 KB Output is correct
13 Correct 1 ms 308 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 296 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 304 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 2 ms 332 KB Output is correct
26 Correct 2 ms 324 KB Output is correct
27 Correct 2 ms 332 KB Output is correct
28 Correct 2 ms 316 KB Output is correct
29 Correct 1 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 302 ms 43640 KB Output is correct
34 Correct 374 ms 52404 KB Output is correct
35 Correct 527 ms 43488 KB Output is correct
36 Correct 487 ms 47356 KB Output is correct
37 Correct 167 ms 42764 KB Output is correct
38 Correct 164 ms 42832 KB Output is correct
39 Correct 145 ms 49720 KB Output is correct
40 Correct 118 ms 49744 KB Output is correct
41 Correct 120 ms 40976 KB Output is correct
42 Correct 123 ms 41900 KB Output is correct
43 Correct 94 ms 40900 KB Output is correct
44 Correct 114 ms 44776 KB Output is correct
45 Correct 125 ms 40924 KB Output is correct
46 Correct 107 ms 40964 KB Output is correct
47 Correct 104 ms 45156 KB Output is correct
48 Correct 100 ms 45112 KB Output is correct
49 Correct 847 ms 44848 KB Output is correct
50 Correct 783 ms 44840 KB Output is correct
51 Correct 363 ms 51648 KB Output is correct
52 Correct 201 ms 51092 KB Output is correct
53 Correct 533 ms 43108 KB Output is correct
54 Correct 304 ms 43748 KB Output is correct
55 Correct 165 ms 42052 KB Output is correct
56 Correct 198 ms 46628 KB Output is correct
57 Correct 325 ms 42588 KB Output is correct
58 Correct 271 ms 43080 KB Output is correct
59 Correct 92 ms 45176 KB Output is correct