답안 #781504

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
781504 2023-07-13T07:03:20 Z vjudge1 말 (IOI15_horses) C++17
100 / 100
714 ms 69108 KB
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5+37;; 
#define ll long long int
set<int> px; // not 1 x positions
ll st[2][N*4]; // st[0] returns multipication, st[1] returns max,
int mod = 1e9+7, n;
vector<int> x, y;

void f(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
}
int m(ll a){
    return a%mod;
}

void update(int v, int l, int r, int pos, int val, int t){
    if(l==r) st[t][v] = val;
    else if(l<r){
        int mid = (r+l) / 2;
        if(pos <= mid) update(v*2, l, mid, pos, val, t);
        else update(v*2+1, mid+1, r, pos, val, t);

        if(t == 0) st[t][v] = m(st[t][v*2]*st[t][v*2+1]);
        else st[t][v] = max (st[t][v*2], st[t][v*2+1]);
    }
}

ll get(int v, int l, int r, int tl, int tr, int t){
    if(l>r || tl > r || l > tr){
        if(t == 0) return 1;
        else return 0;
    }
    else if(l>=tl && r <= tr) return st[t][v];
    else{
        int mid = (r+l) / 2;
       
        if(t == 0) return m(get(v*2, l, mid, tl, tr, t)*get(v*2+1, mid+1, r, tl, tr, t));
        return max (get(v*2, l, mid, tl, tr, t), get(v*2+1, mid+1, r, tl, tr, t));
    }
}

int ans(){
    vector<array<ll, 2>> a;


    int r=n-1;
    ll mx=1, my;

    for(auto i: px){
        int pos=-i;
        mx*=x[pos];
       
        a.push_back({pos, get(1, 0, n-1, pos, r, 1)});
        r=pos-1;
        if(mx>(ll)1e9) break;
    }

    reverse(a.begin(), a.end());
    ll k = 1;

    mx = a[0][0], my=a[0][1];
    for(int i=1; i<a.size(); i++){
        k=m(k*x[a[i][0]]);

        if(a[i][1]*k >= my){
            my=a[i][1];;
            mx=a[i][0];
            k = 1;
        }
        
    }
  
    return m(get(1, 0, n-1, 0, mx, 0)*my);
}

int init(int N, int X[], int Y[]) {
    n=N;
    px.insert(0);

    x.resize(n); y.resize(n);
    for(int i = 0; i < 4*n+37; i++){
        st[0][i] = 1;
    }

    for(int i = 0; i < n; i++){
        x[i] = X[i]; y[i] = Y[i];
    }

    for(int i = 0; i < n; i++){
        if(x[i] != 1) px.insert(-i), update(1, 0, n-1, i, x[i], 0);
        update(1, 0, n-1, i, y[i], 1);
    } 

    return ans();
}

int updateX(int pos, int val) { 

    if(x[pos] > 1 && val == 1){
        if(pos!=0)
        px.erase(-pos);
    }
    else if(x[pos] == 1 && val > 1){
        px.insert(-pos);
    }
    x[pos] = val;

    update(1, 0, n-1, pos, val, 0);

    return ans();
}

int updateY(int pos, int val) {
    y[pos] = val;
    update(1, 0, n-1, pos, val, 1);
    return ans();
}
/*
int main() {
    f();

    int N; cin >> N; 

	int *X = (int*)malloc(sizeof(int)*(unsigned int)N);
	int *Y = (int*)malloc(sizeof(int)*(unsigned int)N);

	for (int i = 0; i < N; i++) {
		cin >> X[i];
	}

	for (int i = 0; i < N; i++) {
		cin >> Y[i];
	}	
    ll f= 1e18; //cout<<f;

    cout<<init(N,X,Y)<<"\n";

	int M; cin >> M;

	for (int i = 0; i < M; i++) {
		int type, pos , val; cin >> type >> pos >> val;

		if (type == 1) {
			cout<<updateX(pos,val)<<"\n";
		} else if (type == 2) {
			cout<<updateY(pos,val)<<"\n";
		}
	}

	return 0;
}
*/

Compilation message

horses.cpp: In function 'int m(long long int)':
horses.cpp:16:13: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   16 |     return a%mod;
      |            ~^~~~
horses.cpp: In function 'int ans()':
horses.cpp:65:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |     for(int i=1; i<a.size(); i++){
      |                  ~^~~~~~~~~
horses.cpp:76:32: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   76 |     return m(get(1, 0, n-1, 0, mx, 0)*my);
      |                                ^~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:79:14: warning: declaration of 'N' shadows a global declaration [-Wshadow]
   79 | int init(int N, int X[], int Y[]) {
      |          ~~~~^
horses.cpp:4:11: note: shadowed declaration is here
    4 | const int N = 5e5+37;;
      |           ^
horses.cpp: In function 'void f()':
horses.cpp:12:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     freopen("in.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
horses.cpp:13:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     freopen("out.txt", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 316 KB Output is correct
20 Correct 0 ms 224 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 3 ms 340 KB Output is correct
28 Correct 3 ms 452 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 2 ms 456 KB Output is correct
31 Correct 3 ms 340 KB Output is correct
32 Correct 3 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 710 ms 56388 KB Output is correct
2 Correct 385 ms 56440 KB Output is correct
3 Correct 401 ms 56372 KB Output is correct
4 Correct 423 ms 56452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 3 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 3 ms 340 KB Output is correct
33 Correct 97 ms 36080 KB Output is correct
34 Correct 97 ms 36120 KB Output is correct
35 Correct 339 ms 66396 KB Output is correct
36 Correct 327 ms 66368 KB Output is correct
37 Correct 138 ms 34256 KB Output is correct
38 Correct 200 ms 47048 KB Output is correct
39 Correct 90 ms 34044 KB Output is correct
40 Correct 299 ms 61428 KB Output is correct
41 Correct 109 ms 34056 KB Output is correct
42 Correct 123 ms 34184 KB Output is correct
43 Correct 291 ms 61760 KB Output is correct
44 Correct 287 ms 61756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 4 ms 340 KB Output is correct
28 Correct 2 ms 448 KB Output is correct
29 Correct 1 ms 316 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 3 ms 340 KB Output is correct
33 Correct 714 ms 60300 KB Output is correct
34 Correct 402 ms 69108 KB Output is correct
35 Correct 385 ms 60184 KB Output is correct
36 Correct 428 ms 64020 KB Output is correct
37 Correct 104 ms 36100 KB Output is correct
38 Correct 92 ms 36112 KB Output is correct
39 Correct 333 ms 66412 KB Output is correct
40 Correct 316 ms 66360 KB Output is correct
41 Correct 143 ms 34504 KB Output is correct
42 Correct 198 ms 46968 KB Output is correct
43 Correct 86 ms 34076 KB Output is correct
44 Correct 294 ms 61400 KB Output is correct
45 Correct 107 ms 34048 KB Output is correct
46 Correct 124 ms 34124 KB Output is correct
47 Correct 289 ms 61764 KB Output is correct
48 Correct 318 ms 61812 KB Output is correct
49 Correct 238 ms 39172 KB Output is correct
50 Correct 177 ms 39256 KB Output is correct
51 Correct 454 ms 68300 KB Output is correct
52 Correct 382 ms 67784 KB Output is correct
53 Correct 649 ms 37376 KB Output is correct
54 Correct 443 ms 50948 KB Output is correct
55 Correct 190 ms 35132 KB Output is correct
56 Correct 387 ms 63192 KB Output is correct
57 Correct 399 ms 35736 KB Output is correct
58 Correct 566 ms 36196 KB Output is correct
59 Correct 289 ms 61748 KB Output is correct