Submission #139888

# Submission time Handle Problem Language Result Execution time Memory
139888 2019-08-01T15:29:48 Z Plurm Horses (IOI15_horses) C++11
100 / 100
625 ms 71164 KB
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
 
const int MOD = 1e9+7;
long double seg1[1048576]; // Sum of log2s
long double seg2[1048576]; // log2(Answer)
int seg3[1048576]; // Range product query
int seg4[1048576]; // Real Answer
int lb[1048576];
int rb[1048576];
int rx[500005];
int ry[500005];

void build(int c, int l, int r){
    lb[c] = l;
    rb[c] = r;
    if(l == r){
        seg1[c] = log2l(rx[l]);
        seg2[c] = log2l(rx[l]) + log2l(ry[l]);
        seg3[c] = rx[l];
        seg4[c] = (1ll * rx[l] * ry[l]) % MOD;
        return;
    }
    int k = (l + r)/2;
    build(2*c,l,k);
    build(2*c+1,k+1,r);
    seg1[c] = seg1[2*c] + seg1[2*c+1];
    seg3[c] = (1ll * seg3[2*c] * seg3[2*c+1]) % MOD;
    if(seg2[2*c] > seg2[2*c+1] + seg1[2*c]){
        seg2[c] = seg2[2*c];
        seg4[c] = seg4[2*c];
    }else{
        seg2[c] = seg2[2*c+1] + seg1[2*c];
        seg4[c] = (1ll * seg4[2*c+1] * seg3[2*c]) % MOD;
    }
}

void update(int c, int idx){
    if(lb[c] == rb[c]){
        seg1[c] = log2l(rx[idx]);
        seg2[c] = log2l(rx[idx]) + log2l(ry[idx]);
        seg3[c] = rx[idx];
        seg4[c] = (1ll * rx[idx] * ry[idx]) % MOD;
        return;
    }
    int k = (lb[c] + rb[c])/2;
    if(idx <= k) update(2*c, idx);
    else update(2*c+1, idx);
    seg1[c] = seg1[2*c] + seg1[2*c+1];
    seg3[c] = (1ll * seg3[2*c] * seg3[2*c+1]) % MOD;
    if(seg2[2*c] > seg2[2*c+1] + seg1[2*c]){
        seg2[c] = seg2[2*c];
        seg4[c] = seg4[2*c];
    }else{
        seg2[c] = seg2[2*c+1] + seg1[2*c];
        seg4[c] = (1ll * seg4[2*c+1] * seg3[2*c]) % MOD;
    }
}

int init(int N, int X[], int Y[]) {
    for(int i = 0; i < N; i++){
        rx[i] = X[i];
        ry[i] = Y[i];
    }
    build(1,0,N-1);
	return seg4[1];
}
 
int updateX(int pos, int val) {
    rx[pos] = val;
    update(1, pos);
    return seg4[1];
}
 
int updateY(int pos, int val) {
    ry[pos] = val;
    update(1, pos);
    return seg4[1];
}

Compilation message

horses.cpp: In function 'void build(int, int, int)':
horses.cpp:22:41: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
         seg4[c] = (1ll * rx[l] * ry[l]) % MOD;
                   ~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp:29:47: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     seg3[c] = (1ll * seg3[2*c] * seg3[2*c+1]) % MOD;
               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp:35:51: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
         seg4[c] = (1ll * seg4[2*c+1] * seg3[2*c]) % MOD;
                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'void update(int, int)':
horses.cpp:44:45: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
         seg4[c] = (1ll * rx[idx] * ry[idx]) % MOD;
                   ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp:51:47: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     seg3[c] = (1ll * seg3[2*c] * seg3[2*c+1]) % MOD;
               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp:57:51: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
         seg4[c] = (1ll * seg4[2*c+1] * seg3[2*c]) % MOD;
                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 380 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 3 ms 504 KB Output is correct
24 Correct 3 ms 504 KB Output is correct
25 Correct 3 ms 504 KB Output is correct
26 Correct 3 ms 504 KB Output is correct
27 Correct 3 ms 504 KB Output is correct
28 Correct 3 ms 504 KB Output is correct
29 Correct 3 ms 504 KB Output is correct
30 Correct 3 ms 504 KB Output is correct
31 Correct 3 ms 504 KB Output is correct
32 Correct 3 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 223 ms 58416 KB Output is correct
2 Correct 353 ms 58492 KB Output is correct
3 Correct 320 ms 62288 KB Output is correct
4 Correct 368 ms 66084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 380 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 3 ms 504 KB Output is correct
24 Correct 3 ms 504 KB Output is correct
25 Correct 3 ms 504 KB Output is correct
26 Correct 3 ms 504 KB Output is correct
27 Correct 3 ms 504 KB Output is correct
28 Correct 3 ms 504 KB Output is correct
29 Correct 3 ms 504 KB Output is correct
30 Correct 3 ms 504 KB Output is correct
31 Correct 3 ms 504 KB Output is correct
32 Correct 3 ms 504 KB Output is correct
33 Correct 179 ms 61544 KB Output is correct
34 Correct 179 ms 61404 KB Output is correct
35 Correct 167 ms 68480 KB Output is correct
36 Correct 166 ms 68320 KB Output is correct
37 Correct 183 ms 59580 KB Output is correct
38 Correct 149 ms 60536 KB Output is correct
39 Correct 173 ms 59540 KB Output is correct
40 Correct 159 ms 63352 KB Output is correct
41 Correct 171 ms 59524 KB Output is correct
42 Correct 169 ms 59544 KB Output is correct
43 Correct 152 ms 63832 KB Output is correct
44 Correct 152 ms 63736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 3 ms 504 KB Output is correct
24 Correct 3 ms 504 KB Output is correct
25 Correct 2 ms 504 KB Output is correct
26 Correct 3 ms 504 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 3 ms 504 KB Output is correct
29 Correct 3 ms 504 KB Output is correct
30 Correct 3 ms 632 KB Output is correct
31 Correct 3 ms 504 KB Output is correct
32 Correct 3 ms 504 KB Output is correct
33 Correct 226 ms 62292 KB Output is correct
34 Correct 373 ms 71164 KB Output is correct
35 Correct 321 ms 62292 KB Output is correct
36 Correct 327 ms 66040 KB Output is correct
37 Correct 183 ms 61560 KB Output is correct
38 Correct 181 ms 61492 KB Output is correct
39 Correct 166 ms 68344 KB Output is correct
40 Correct 164 ms 68344 KB Output is correct
41 Correct 179 ms 59672 KB Output is correct
42 Correct 147 ms 60536 KB Output is correct
43 Correct 169 ms 59512 KB Output is correct
44 Correct 158 ms 63376 KB Output is correct
45 Correct 185 ms 59512 KB Output is correct
46 Correct 171 ms 59688 KB Output is correct
47 Correct 152 ms 63736 KB Output is correct
48 Correct 152 ms 63912 KB Output is correct
49 Correct 346 ms 63728 KB Output is correct
50 Correct 353 ms 63436 KB Output is correct
51 Correct 251 ms 70264 KB Output is correct
52 Correct 258 ms 69884 KB Output is correct
53 Correct 625 ms 61860 KB Output is correct
54 Correct 227 ms 62328 KB Output is correct
55 Correct 241 ms 60632 KB Output is correct
56 Correct 232 ms 65272 KB Output is correct
57 Correct 257 ms 61176 KB Output is correct
58 Correct 260 ms 61688 KB Output is correct
59 Correct 155 ms 63736 KB Output is correct