답안 #228756

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
228756 2020-05-02T13:21:59 Z Rakhmand Fire (JOI20_ho_t5) C++14
0 / 100
1000 ms 7544 KB
// I feel still alive.
//  Created by existence on 18/04/2003.
//  Copyright © 2020 Rakhman. All rights reserved.

#include <vector>
#include <map>
#include <set>
#include <deque>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <iterator>

#define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define S second
#define F first
#define nl '\n'

const long long mxn = 1e6 + 10;
const long long mod = 1e9 + 7;
const long long inf = 1e18;

typedef long long llong;

using namespace std;

void istxt(bool yes){
    if(yes == 1){
        freopen("balancing.in", "r", stdin);
        freopen("balancing.out", "w", stdout);
    }else{
        freopen("/Users/rakhmanabdirashov/Desktop/folder/Programming/Road2Master/Road2Master/input.txt", "r", stdin);
    }
}

int n, Q, b[mxn], l[mxn], mx[mxn];
llong ans[mxn];

struct query{
    int t, l, r, ind;
}q[mxn];

bool cmp(query a, query b){
    return a.t < b.t;
}

int main () {
    ios;
    //istxt(0);
    cin >> n >> Q;
    for(int i = 1; i <= n; i++){
        cin >> b[i];
        mx[i] = b[i];
        l[i] = i;
    }
    for(int i = 1; i <= Q; i++){
        cin >> q[i].t >> q[i].l >> q[i].r;
        q[i].ind = i;
    }
    sort(q + 1, q + Q + 1, cmp);
    for(int qq = 1; qq <= Q; qq++){
        int last = q[qq].t - q[qq - 1].t;
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= last; j++){
                l[i]--;
                if(l[i] <= 0) break;
                mx[i] = max(mx[i], b[l[i]]);
            }
        }
        llong sum = 0;
        for(int i = q[qq].l; i <= q[qq].r; i++){
            sum += mx[i];
        }
        ans[q[qq].ind] = sum;
    }
    for(int i = 1; i <= n; i++){
        cout << ans[i] << nl;
    }
    return 0;
}
/*
 5 5
 9 3 2 6 5
 1 1 3
 2 1 5
 3 2 5
 4 3 3
 5 3 5
 
 10 10
 3 1 4 1 5 9 2 6 5 3
 1 1 6
 2 8 10
 4 2 7
 8 3 3
 6 1 10
 3 2 8
 5 1 9
 7 4 5
 9 7 9
 10 10 10
 
 10 10
 3 1 4 1 5 9 2 6 5 3
 1 6 6
 2 8 8
 4 2 2
 8 3 3
 6 1 1
 3 4 4
 5 5 5
 7 10 10
 9 8 8
 10 7 7
 
 10 10
 3 1 4 1 5 9 2 6 5 3
 7 1 6
 7 8 10
 7 2 7
 7 3 3
 7 1 10
 7 2 8
 7 1 9
 7 4 5
 7 7 9
 7 10 10
 
 20 20
 2 1 2 2 1 1 1 1 2 2 2 1 2 1 1 2 1 2 1 1
 1 1 14
 2 3 18
 4 10 15
 8 2 17
 9 20 20
 4 8 19
 7 2 20
 11 1 5
 13 2 8
 20 1 20
 2 12 15
 7 1 14
 12 7 18
 14 2 17
 9 19 20
 12 12 12
 6 2 15
 11 2 15
 19 12 17
 4 1 20
 */

Compilation message

ho_t5.cpp: In function 'void istxt(bool)':
ho_t5.cpp:29:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen("balancing.in", "r", stdin);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
ho_t5.cpp:30:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen("balancing.out", "w", stdout);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ho_t5.cpp:32:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen("/Users/rakhmanabdirashov/Desktop/folder/Programming/Road2Master/Road2Master/input.txt", "r", stdin);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 5 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Execution timed out 1091 ms 5624 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Execution timed out 1092 ms 7544 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1094 ms 7288 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 5 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -