Submission #6613

# Submission time Handle Problem Language Result Execution time Memory
6613 2014-07-01T17:49:54 Z tncks0121 역사적 조사 (JOI14_historical) C++
100 / 100
2052 ms 25204 KB
#define _CRT_SECURE_NO_WARNINGS
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <functional>
#include <vector>
#include <deque>
#include <utility>
#include <bitset>
#include <limits.h> 
#include <time.h>
 
using namespace std;
typedef long long ll;
typedef unsigned long long llu;
typedef double lf;
typedef unsigned int uint;
typedef long double llf;
typedef pair<int, int> pii;
 
const int N_ = 150005;
const int B = 110;
int N, Q, X[N_], S[N_], SN, P[N_];
vector<int> W[N_];
ll precalc[N_/B][N_/B], C[N_];
 
int main() {
    scanf("%d%d", &N, &Q);
    for(int i = 0; i < N; i++) {
        scanf("%d", X+i);
        S[i] = X[i];
    }
 
    sort(S, S+N);
    SN = unique(S, S+N) - S;
     
    for(int i = 0; i < N; i++) {
        P[i] = lower_bound(S, S+SN, X[i]) - S;
        W[P[i]].push_back(i);
    }
 
    for(int i = 0; i < N; i += B) {
        for(int j = 0; j < N; j++) C[j] = 0;
        ll val = 0;
        for(int j = i; j < N; j++) {
            C[P[j]] += (ll)X[j];
            if(val < C[P[j]]) val = C[P[j]];
            if(j % B == 0) precalc[i/B][j/B] = val;
        }
    }
 
    while(Q--) {
        int a, b; scanf("%d%d", &a, &b); --a; --b;
        int x = a, y = b;
        ll ans = 0;
        for(; x % B != 0; ++x) {
            ll val = (ll)X[x] * (lower_bound(W[P[x]].begin(), W[P[x]].end(), b+1) - lower_bound(W[P[x]].begin(), W[P[x]].end(), a));
            if(val > ans) ans = val;
        }
        for(; y % B != 0; --y) {
            ll val = (ll)X[y] * (lower_bound(W[P[y]].begin(), W[P[y]].end(), b+1) - lower_bound(W[P[y]].begin(), W[P[y]].end(), a));
            if(val > ans) ans = val;
        }
        ans = max(ans, precalc[x/B][y/B]);
 
        printf("%lld\n", ans);
    }
 
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 22168 KB Output is correct
2 Correct 0 ms 22168 KB Output is correct
3 Correct 0 ms 22168 KB Output is correct
4 Correct 0 ms 22168 KB Output is correct
5 Correct 0 ms 22168 KB Output is correct
6 Correct 0 ms 22168 KB Output is correct
7 Correct 0 ms 22168 KB Output is correct
8 Correct 0 ms 22168 KB Output is correct
9 Correct 0 ms 22168 KB Output is correct
10 Correct 0 ms 22168 KB Output is correct
11 Correct 0 ms 22168 KB Output is correct
12 Correct 0 ms 22168 KB Output is correct
13 Correct 0 ms 22168 KB Output is correct
14 Correct 0 ms 22168 KB Output is correct
15 Correct 0 ms 22168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 22168 KB Output is correct
2 Correct 0 ms 22168 KB Output is correct
3 Correct 4 ms 22168 KB Output is correct
4 Correct 16 ms 22168 KB Output is correct
5 Correct 28 ms 22168 KB Output is correct
6 Correct 52 ms 22168 KB Output is correct
7 Correct 52 ms 22168 KB Output is correct
8 Correct 56 ms 22168 KB Output is correct
9 Correct 64 ms 22168 KB Output is correct
10 Correct 28 ms 22168 KB Output is correct
11 Correct 32 ms 22168 KB Output is correct
12 Correct 32 ms 22168 KB Output is correct
13 Correct 36 ms 22168 KB Output is correct
14 Correct 40 ms 22168 KB Output is correct
15 Correct 32 ms 22168 KB Output is correct
16 Correct 64 ms 22168 KB Output is correct
17 Correct 48 ms 22168 KB Output is correct
18 Correct 32 ms 22168 KB Output is correct
19 Correct 32 ms 22168 KB Output is correct
20 Correct 28 ms 22168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 22168 KB Output is correct
2 Correct 0 ms 22168 KB Output is correct
3 Correct 0 ms 22168 KB Output is correct
4 Correct 0 ms 22168 KB Output is correct
5 Correct 0 ms 22168 KB Output is correct
6 Correct 0 ms 22168 KB Output is correct
7 Correct 0 ms 22168 KB Output is correct
8 Correct 4 ms 22300 KB Output is correct
9 Correct 32 ms 22432 KB Output is correct
10 Correct 68 ms 22728 KB Output is correct
11 Correct 1524 ms 22692 KB Output is correct
12 Correct 292 ms 22696 KB Output is correct
13 Correct 492 ms 22828 KB Output is correct
14 Correct 732 ms 23488 KB Output is correct
15 Correct 1032 ms 23884 KB Output is correct
16 Correct 528 ms 25204 KB Output is correct
17 Correct 464 ms 22696 KB Output is correct
18 Correct 764 ms 22700 KB Output is correct
19 Correct 396 ms 25204 KB Output is correct
20 Correct 276 ms 25204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 132 ms 22168 KB Output is correct
2 Correct 220 ms 22300 KB Output is correct
3 Correct 288 ms 22432 KB Output is correct
4 Correct 360 ms 22564 KB Output is correct
5 Correct 472 ms 22696 KB Output is correct
6 Correct 760 ms 22564 KB Output is correct
7 Correct 1276 ms 22564 KB Output is correct
8 Correct 1596 ms 22568 KB Output is correct
9 Correct 1596 ms 22644 KB Output is correct
10 Correct 1252 ms 22940 KB Output is correct
11 Correct 1816 ms 22808 KB Output is correct
12 Correct 2052 ms 22696 KB Output is correct
13 Correct 1464 ms 22828 KB Output is correct
14 Correct 1164 ms 23224 KB Output is correct
15 Correct 1032 ms 23884 KB Output is correct
16 Correct 1112 ms 23488 KB Output is correct
17 Correct 1160 ms 23488 KB Output is correct
18 Correct 1144 ms 23356 KB Output is correct
19 Correct 1172 ms 23224 KB Output is correct
20 Correct 1200 ms 23224 KB Output is correct
21 Correct 1228 ms 23224 KB Output is correct
22 Correct 1200 ms 23092 KB Output is correct
23 Correct 1200 ms 23092 KB Output is correct
24 Correct 1232 ms 23092 KB Output is correct
25 Correct 1224 ms 22940 KB Output is correct