답안 #40081

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
40081 2018-01-26T13:29:45 Z igzi 말 (IOI15_horses) C++14
100 / 100
173 ms 78864 KB
#include <bits/stdc++.h>
#include "horses.h"
#define maxN 500005
#define mod 1000000007

using namespace std;

struct segment{
long long a,b;
double la,lb;};
segment seg[4*maxN];
vector <long long> x,y;

void build(int n,int l,int d){
if(l==d){
    seg[n].a=x[l];
    seg[n].b=(x[l]*y[l])%mod;
    seg[n].la=log2(x[l]);
    seg[n].lb=log2(y[l])+seg[n].la;
}
else{
    int m=(l+d)/2;
    build(2*n,l,m);
    build(2*n+1,m+1,d);
    seg[n].a=(seg[2*n].a*seg[2*n+1].a)%mod;
    seg[n].la=seg[2*n].la+seg[2*n+1].la;
    if(seg[2*n].lb>seg[2*n+1].lb+seg[2*n].la){
        seg[n].lb=seg[2*n].lb;
        seg[n].b=seg[2*n].b;
    }
    else{
       seg[n].lb=seg[2*n+1].lb+seg[2*n].la;
        seg[n].b=(seg[2*n+1].b*seg[2*n].a)%mod;
    }
}
}
void updatex(int n,int l,int d,int p,long long v){
if(l==d){
    x[l]=v;
    seg[n].a=x[l];
    seg[n].b=(x[l]*y[l])%mod;
    seg[n].la=log2(x[l]);
    seg[n].lb=log2(y[l])+seg[n].la;
}
else{
    int m=(l+d)/2;
    if(p<=m) updatex(2*n,l,m,p,v);
    else updatex(2*n+1,m+1,d,p,v);
    seg[n].a=(seg[2*n].a*seg[2*n+1].a)%mod;
    seg[n].la=seg[2*n].la+seg[2*n+1].la;
    if(seg[2*n].lb>seg[2*n+1].lb+seg[2*n].la){
        seg[n].lb=seg[2*n].lb;
        seg[n].b=seg[2*n].b;
    }
    else{
       seg[n].lb=seg[2*n+1].lb+seg[2*n].la;
        seg[n].b=(seg[2*n+1].b*seg[2*n].a)%mod;
    }
}
}
void updatey(int n,int l,int d,int p,long long v){
if(l==d){
    y[l]=v;
    seg[n].b=(x[l]*y[l])%mod;
    seg[n].lb=log2(y[l])+seg[n].la;
}
else{
    int m=(l+d)/2;
    if(p<=m) updatey(2*n,l,m,p,v);
    else updatey(2*n+1,m+1,d,p,v);
    seg[n].a=(seg[2*n].a*seg[2*n+1].a)%mod;
    seg[n].la=seg[2*n].la+seg[2*n+1].la;
    if(seg[2*n].lb>seg[2*n+1].lb+seg[2*n].la){
        seg[n].lb=seg[2*n].lb;
        seg[n].b=seg[2*n].b;
    }
    else{
       seg[n].lb=seg[2*n+1].lb+seg[2*n].la;
        seg[n].b=(seg[2*n+1].b*seg[2*n].a)%mod;
    }
}
}

int init(int n,int a[],int b[]){
int i;
long long ans;
for(i=0;i<n;i++){
    x.push_back(a[i]%mod);
    y.push_back(b[i]%mod);
}
build(1,0,n-1);
ans=seg[1].b%mod;
return (int) ans;
}
int updateX(int pos,int val){
long long ans;
updatex(1,0,x.size()-1,pos,(long long) val);
ans=seg[1].b%mod;
return (int) ans;
}
int updateY(int pos,int val){
long long ans;
updatey(1,0,y.size()-1,pos,(long long) val);
ans=seg[1].b%mod;
return (int) ans;
}

Compilation message

horses.cpp: In function 'int updateX(int, int)':
horses.cpp:97:43: warning: conversion to 'int' from 'std::vector<long long int>::size_type {aka long unsigned int}' may alter its value [-Wconversion]
 updatex(1,0,x.size()-1,pos,(long long) val);
                                           ^
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:103:43: warning: conversion to 'int' from 'std::vector<long long int>::size_type {aka long unsigned int}' may alter its value [-Wconversion]
 updatey(1,0,y.size()-1,pos,(long long) val);
                                           ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 64540 KB Output is correct
2 Correct 0 ms 64540 KB Output is correct
3 Correct 0 ms 64540 KB Output is correct
4 Correct 0 ms 64540 KB Output is correct
5 Correct 0 ms 64540 KB Output is correct
6 Correct 0 ms 64540 KB Output is correct
7 Correct 0 ms 64540 KB Output is correct
8 Correct 0 ms 64540 KB Output is correct
9 Correct 0 ms 64540 KB Output is correct
10 Correct 0 ms 64540 KB Output is correct
11 Correct 0 ms 64540 KB Output is correct
12 Correct 0 ms 64540 KB Output is correct
13 Correct 0 ms 64540 KB Output is correct
14 Correct 0 ms 64540 KB Output is correct
15 Correct 0 ms 64540 KB Output is correct
16 Correct 0 ms 64540 KB Output is correct
17 Correct 0 ms 64540 KB Output is correct
18 Correct 0 ms 64540 KB Output is correct
19 Correct 0 ms 64540 KB Output is correct
20 Correct 0 ms 64540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 64540 KB Output is correct
2 Correct 0 ms 64540 KB Output is correct
3 Correct 0 ms 64540 KB Output is correct
4 Correct 0 ms 64540 KB Output is correct
5 Correct 0 ms 64540 KB Output is correct
6 Correct 0 ms 64540 KB Output is correct
7 Correct 0 ms 64540 KB Output is correct
8 Correct 0 ms 64540 KB Output is correct
9 Correct 0 ms 64540 KB Output is correct
10 Correct 0 ms 64540 KB Output is correct
11 Correct 0 ms 64540 KB Output is correct
12 Correct 0 ms 64540 KB Output is correct
13 Correct 0 ms 64540 KB Output is correct
14 Correct 0 ms 64540 KB Output is correct
15 Correct 0 ms 64540 KB Output is correct
16 Correct 0 ms 64540 KB Output is correct
17 Correct 0 ms 64540 KB Output is correct
18 Correct 0 ms 64540 KB Output is correct
19 Correct 0 ms 64540 KB Output is correct
20 Correct 0 ms 64540 KB Output is correct
21 Correct 0 ms 64540 KB Output is correct
22 Correct 0 ms 64540 KB Output is correct
23 Correct 1 ms 64540 KB Output is correct
24 Correct 1 ms 64540 KB Output is correct
25 Correct 1 ms 64540 KB Output is correct
26 Correct 1 ms 64540 KB Output is correct
27 Correct 1 ms 64540 KB Output is correct
28 Correct 1 ms 64540 KB Output is correct
29 Correct 1 ms 64540 KB Output is correct
30 Correct 0 ms 64540 KB Output is correct
31 Correct 1 ms 64540 KB Output is correct
32 Correct 1 ms 64540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 85 ms 78864 KB Output is correct
2 Correct 167 ms 78864 KB Output is correct
3 Correct 123 ms 78864 KB Output is correct
4 Correct 166 ms 78864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 64540 KB Output is correct
2 Correct 0 ms 64540 KB Output is correct
3 Correct 0 ms 64540 KB Output is correct
4 Correct 0 ms 64540 KB Output is correct
5 Correct 0 ms 64540 KB Output is correct
6 Correct 0 ms 64540 KB Output is correct
7 Correct 0 ms 64540 KB Output is correct
8 Correct 0 ms 64540 KB Output is correct
9 Correct 0 ms 64540 KB Output is correct
10 Correct 0 ms 64540 KB Output is correct
11 Correct 0 ms 64540 KB Output is correct
12 Correct 0 ms 64540 KB Output is correct
13 Correct 0 ms 64540 KB Output is correct
14 Correct 0 ms 64540 KB Output is correct
15 Correct 0 ms 64540 KB Output is correct
16 Correct 0 ms 64540 KB Output is correct
17 Correct 0 ms 64540 KB Output is correct
18 Correct 0 ms 64540 KB Output is correct
19 Correct 0 ms 64540 KB Output is correct
20 Correct 0 ms 64540 KB Output is correct
21 Correct 0 ms 64540 KB Output is correct
22 Correct 0 ms 64540 KB Output is correct
23 Correct 1 ms 64540 KB Output is correct
24 Correct 1 ms 64540 KB Output is correct
25 Correct 1 ms 64540 KB Output is correct
26 Correct 1 ms 64540 KB Output is correct
27 Correct 1 ms 64540 KB Output is correct
28 Correct 1 ms 64540 KB Output is correct
29 Correct 1 ms 64540 KB Output is correct
30 Correct 1 ms 64540 KB Output is correct
31 Correct 1 ms 64540 KB Output is correct
32 Correct 1 ms 64540 KB Output is correct
33 Correct 57 ms 78864 KB Output is correct
34 Correct 50 ms 78864 KB Output is correct
35 Correct 75 ms 78864 KB Output is correct
36 Correct 83 ms 78864 KB Output is correct
37 Correct 38 ms 78864 KB Output is correct
38 Correct 62 ms 78864 KB Output is correct
39 Correct 42 ms 78864 KB Output is correct
40 Correct 60 ms 78864 KB Output is correct
41 Correct 43 ms 78864 KB Output is correct
42 Correct 24 ms 78864 KB Output is correct
43 Correct 46 ms 78864 KB Output is correct
44 Correct 61 ms 78864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 64540 KB Output is correct
2 Correct 0 ms 64540 KB Output is correct
3 Correct 0 ms 64540 KB Output is correct
4 Correct 0 ms 64540 KB Output is correct
5 Correct 0 ms 64540 KB Output is correct
6 Correct 0 ms 64540 KB Output is correct
7 Correct 0 ms 64540 KB Output is correct
8 Correct 0 ms 64540 KB Output is correct
9 Correct 0 ms 64540 KB Output is correct
10 Correct 0 ms 64540 KB Output is correct
11 Correct 0 ms 64540 KB Output is correct
12 Correct 0 ms 64540 KB Output is correct
13 Correct 0 ms 64540 KB Output is correct
14 Correct 0 ms 64540 KB Output is correct
15 Correct 0 ms 64540 KB Output is correct
16 Correct 0 ms 64540 KB Output is correct
17 Correct 0 ms 64540 KB Output is correct
18 Correct 0 ms 64540 KB Output is correct
19 Correct 0 ms 64540 KB Output is correct
20 Correct 0 ms 64540 KB Output is correct
21 Correct 0 ms 64540 KB Output is correct
22 Correct 0 ms 64540 KB Output is correct
23 Correct 1 ms 64540 KB Output is correct
24 Correct 1 ms 64540 KB Output is correct
25 Correct 1 ms 64540 KB Output is correct
26 Correct 1 ms 64540 KB Output is correct
27 Correct 1 ms 64540 KB Output is correct
28 Correct 1 ms 64540 KB Output is correct
29 Correct 0 ms 64540 KB Output is correct
30 Correct 0 ms 64540 KB Output is correct
31 Correct 0 ms 64540 KB Output is correct
32 Correct 1 ms 64540 KB Output is correct
33 Correct 93 ms 78864 KB Output is correct
34 Correct 173 ms 78864 KB Output is correct
35 Correct 126 ms 78864 KB Output is correct
36 Correct 147 ms 78864 KB Output is correct
37 Correct 47 ms 78864 KB Output is correct
38 Correct 73 ms 78864 KB Output is correct
39 Correct 100 ms 78864 KB Output is correct
40 Correct 92 ms 78864 KB Output is correct
41 Correct 43 ms 78864 KB Output is correct
42 Correct 59 ms 78864 KB Output is correct
43 Correct 43 ms 78864 KB Output is correct
44 Correct 52 ms 78864 KB Output is correct
45 Correct 49 ms 78864 KB Output is correct
46 Correct 35 ms 78864 KB Output is correct
47 Correct 53 ms 78864 KB Output is correct
48 Correct 62 ms 78864 KB Output is correct
49 Correct 151 ms 78864 KB Output is correct
50 Correct 143 ms 78864 KB Output is correct
51 Correct 135 ms 78864 KB Output is correct
52 Correct 132 ms 78864 KB Output is correct
53 Correct 111 ms 78864 KB Output is correct
54 Correct 92 ms 78864 KB Output is correct
55 Correct 62 ms 78864 KB Output is correct
56 Correct 96 ms 78864 KB Output is correct
57 Correct 80 ms 78864 KB Output is correct
58 Correct 92 ms 78864 KB Output is correct
59 Correct 76 ms 78864 KB Output is correct