답안 #153979

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
153979 2019-09-17T16:01:46 Z alexandra_udristoiu 말 (IOI15_horses) C++14
100 / 100
439 ms 55288 KB
#include<iostream>
#include<set>
#include "horses.h"
#define DIM 500005
#define mod 1000000007
#define f first
#define s second
using namespace std;
static int n;
static int x[DIM], y[DIM], lst[DIM], ym[DIM];
static pair<int, int> aint[4 * DIM], aux;
static set< pair<int, int> > w;
static void build(int nod, int st, int dr){
    if(st == dr){
        aint[nod] = make_pair(x[st], y[st]);
    }
    else{
        int mid = (st + dr) / 2;
        build(2 * nod, st, mid);
        build(2 * nod + 1, mid + 1, dr);
        aint[nod].f = aint[2 * nod].f * 1LL * aint[2 * nod + 1].f % mod;
        aint[nod].s = max(aint[2 * nod].s, aint[2 * nod + 1].s);
    }
}
static void update(int nod, int st, int dr, int p){
    if(st == dr){
        aint[nod] = make_pair(x[st], y[st]);
    }
    else{
        int mid = (st + dr) / 2;
        if(p <= mid){
            update(2 * nod, st, mid, p);
        }
        else{
            update(2 * nod + 1, mid + 1, dr, p);
        }
        aint[nod].f = aint[2 * nod].f * 1LL * aint[2 * nod + 1].f % mod;
        aint[nod].s = max(aint[2 * nod].s, aint[2 * nod + 1].s);
    }
}
static void query(int nod, int st, int dr, int p, int u){
    if(p <= st && dr <= u){
        if(aux.f != 0){
            aux.f = aux.f * 1LL * aint[nod].f % mod;
        }
        aux.s = max(aux.s, aint[nod].s);
    }
    else{
        int mid = (st + dr) / 2;
        if(p <= mid){
            query(2 * nod, st, mid, p, u);
        }
        if(u > mid){
            query(2 * nod + 1, mid + 1, dr, p, u);
        }
    }
}
static int solve(){
    int i, ind, ymax;
    long long val, sol;
    set< pair<int, int> > :: iterator it;
    val = 1;
    it = w.end();
    it--;
    for(; it != w.begin(); it--){
        val *= x[ it->f ];
        if(val > 1000000000){
            break;
        }
    }
    val = 1;
    sol = ymax = y[ it->f ];
    ind = it->f;
    it++;
    for(; it != w.end(); it++){
        val *= x[ it->f ];
        if(sol < val * ym[it->f]){
            sol = val * ym[it->f];
            ymax = ym[it->f];
            ind = it->s;
        }
    }
    aux = make_pair(1, 0);
    query(1, 1, n, 1, ind);
    return aux.f * 1LL * ymax % mod;
}
int init(int N, int X[], int Y[]) {
	n = N;
	w.insert( make_pair(0, 0) );
	int lst;
	for(int i = 1; i <= n; i++){
        x[i] = X[i - 1];
        y[i] = Y[i - 1];
	}
	build(1, 1, n);
	for(int i = 1; i <= n; i++){
        if(x[i] != 1){
            ym[i] = y[i];
            w.insert( make_pair(i, i) );
        }
        else{
            if(x[i - 1] != 1){
                lst = i;
            }
            if(x[i + 1] != 1){
                w.insert( make_pair(lst, i) );
                aux = make_pair(0, 0);
                query(1, 1, n, lst, i);
                ym[lst] = aux.s;
            }
        }
	}
	return solve();
}
int updateX(int pos, int val) {
    pos++;
    set< pair<int, int> > :: iterator it;
    pair<int, int> a;
    if(x[pos] == 1){
        it = w.lower_bound( make_pair(pos + 1, 0) );
        it--;
        a = *it;
        w.erase(it);
        if(a.f != pos){
            w.insert( make_pair(a.f, pos - 1) );
            aux = make_pair(0, 0);
            query(1, 1, n, a.f, pos - 1);
            ym[a.f] = aux.s;
        }
        if(a.s != pos){
            w.insert( make_pair(pos + 1, a.s) );
            aux = make_pair(0, 0);
            query(1, 1, n, pos + 1, a.s);
            ym[pos + 1] = aux.s;
        }
        w.insert( make_pair(pos, pos) );
        ym[pos] = y[pos];
    }
    x[pos] = val;
    update(1, 1, n, pos);
    if(x[pos] == 1){
        w.erase( make_pair(pos, pos) );
        a = make_pair(pos, pos);
        if(x[pos - 1] == 1){
            it = w.lower_bound( make_pair(pos, pos) );
            it--;
            a.f = it->f;
            w.erase(it);
        }
        if(x[pos + 1] == 1){
            it = w.lower_bound( make_pair(pos, pos) );
            a.s = it->s;
            w.erase(it);
        }
        w.insert(a);
        aux = make_pair(0, 0);
        query(1, 1, n, a.f, a.s);
        ym[a.f] = aux.s;
    }
	return solve();
}
int updateY(int pos, int val) {
    pos++;
    y[pos] = val;
    update(1, 1, n, pos);
    set< pair<int, int> > :: iterator it;
    it = w.lower_bound( make_pair(pos + 1, 0) );
    it--;
    aux = make_pair(0, 0);
    query(1, 1, n, it->f, it->s);
    ym[it->f] = aux.s;
	return solve();
}

Compilation message

horses.cpp: In function 'void build(int, int, int)':
horses.cpp:21:67: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
         aint[nod].f = aint[2 * nod].f * 1LL * aint[2 * nod + 1].f % mod;
                                                                   ^
horses.cpp: In function 'void update(int, int, int, int)':
horses.cpp:37:67: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
         aint[nod].f = aint[2 * nod].f * 1LL * aint[2 * nod + 1].f % mod;
                                                                   ^
horses.cpp: In function 'void query(int, int, int, int, int)':
horses.cpp:44:47: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
             aux.f = aux.f * 1LL * aint[nod].f % mod;
                                               ^
horses.cpp: In function 'int solve()':
horses.cpp:85:31: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     return aux.f * 1LL * ymax % mod;
                               ^
horses.cpp:59:9: warning: unused variable 'i' [-Wunused-variable]
     int i, ind, ymax;
         ^
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:90:6: warning: declaration of 'lst' shadows a global declaration [-Wshadow]
  int lst;
      ^~~
horses.cpp:10:28: note: shadowed declaration is here
 static int x[DIM], y[DIM], lst[DIM], ym[DIM];
                            ^~~
horses.cpp: At global scope:
horses.cpp:10:28: warning: 'lst' defined but not used [-Wunused-variable]
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:109:25: warning: 'lst' may be used uninitialized in this function [-Wmaybe-uninitialized]
                 ym[lst] = aux.s;
                         ^
# 결과 실행 시간 메모리 Grader output
1 Correct 3 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 364 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 380 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 380 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 4 ms 380 KB Output is correct
19 Correct 0 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 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 348 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 404 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 404 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 4 ms 504 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 3 ms 504 KB Output is correct
26 Correct 3 ms 504 KB Output is correct
27 Correct 4 ms 504 KB Output is correct
28 Correct 4 ms 504 KB Output is correct
29 Correct 3 ms 376 KB Output is correct
30 Correct 3 ms 504 KB Output is correct
31 Correct 3 ms 376 KB Output is correct
32 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 349 ms 45628 KB Output is correct
2 Correct 439 ms 44356 KB Output is correct
3 Correct 394 ms 46328 KB Output is correct
4 Correct 340 ms 45116 KB Output is correct
# 결과 실행 시간 메모리 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 348 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 380 KB Output is correct
16 Correct 3 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 376 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 3 ms 504 KB Output is correct
26 Correct 3 ms 504 KB Output is correct
27 Correct 4 ms 376 KB Output is correct
28 Correct 4 ms 504 KB Output is correct
29 Correct 3 ms 376 KB Output is correct
30 Correct 0 ms 504 KB Output is correct
31 Correct 3 ms 376 KB Output is correct
32 Correct 4 ms 376 KB Output is correct
33 Correct 61 ms 22612 KB Output is correct
34 Correct 60 ms 22776 KB Output is correct
35 Correct 270 ms 52856 KB Output is correct
36 Correct 267 ms 52728 KB Output is correct
37 Correct 55 ms 19704 KB Output is correct
38 Correct 265 ms 44880 KB Output is correct
39 Correct 39 ms 18552 KB Output is correct
40 Correct 250 ms 47968 KB Output is correct
41 Correct 39 ms 18680 KB Output is correct
42 Correct 45 ms 18624 KB Output is correct
43 Correct 238 ms 48280 KB Output is correct
44 Correct 237 ms 48204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 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 12 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 3 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 3 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 8 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 3 ms 504 KB Output is correct
26 Correct 3 ms 504 KB Output is correct
27 Correct 4 ms 504 KB Output is correct
28 Correct 4 ms 504 KB Output is correct
29 Correct 3 ms 376 KB Output is correct
30 Correct 3 ms 504 KB Output is correct
31 Correct 3 ms 376 KB Output is correct
32 Correct 4 ms 376 KB Output is correct
33 Correct 351 ms 46724 KB Output is correct
34 Correct 422 ms 55288 KB Output is correct
35 Correct 392 ms 46628 KB Output is correct
36 Correct 345 ms 50388 KB Output is correct
37 Correct 61 ms 22648 KB Output is correct
38 Correct 64 ms 22648 KB Output is correct
39 Correct 270 ms 52852 KB Output is correct
40 Correct 267 ms 52728 KB Output is correct
41 Correct 59 ms 19804 KB Output is correct
42 Correct 265 ms 44964 KB Output is correct
43 Correct 40 ms 18552 KB Output is correct
44 Correct 246 ms 47828 KB Output is correct
45 Correct 38 ms 18556 KB Output is correct
46 Correct 44 ms 18680 KB Output is correct
47 Correct 234 ms 48248 KB Output is correct
48 Correct 231 ms 48232 KB Output is correct
49 Correct 271 ms 26616 KB Output is correct
50 Correct 263 ms 26680 KB Output is correct
51 Correct 410 ms 54688 KB Output is correct
52 Correct 366 ms 54240 KB Output is correct
53 Correct 351 ms 23692 KB Output is correct
54 Correct 413 ms 46744 KB Output is correct
55 Correct 133 ms 19576 KB Output is correct
56 Correct 372 ms 49632 KB Output is correct
57 Correct 119 ms 20396 KB Output is correct
58 Correct 184 ms 20632 KB Output is correct
59 Correct 235 ms 48376 KB Output is correct