Submission #259255

# Submission time Handle Problem Language Result Execution time Memory
259255 2020-08-07T13:15:33 Z admin 역사적 조사 (JOI14_historical) C++14
40 / 100
4000 ms 101508 KB
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define svec(x) sort(x.begin(), x.end())
#define press(x) x.erase(unique(x.begin(), x.end()), x.end())
#define lb(x, v) lower_bound(x.begin(), x.end(), v)
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
 
vector<pair<pii, int> > cmp;
pii qu[100010];
int n, q, arr[100010], cha[100010], cnt[100010];
vector<int> id;
LL ans[100010];
 
priority_queue<LL> pq, del;
inline void dlt(LL a){del.push(a);}
inline void in(LL a){pq.push(a);}
inline LL tp(){
    while(!del.empty()){
        if(del.top()==pq.top()){
            del.pop(); pq.pop();
        }
        else break;
    }
    return pq.top();
}
 
inline void ins(int num){
    num=arr[num];
    dlt((LL)cha[num]*cnt[num]);
    cnt[num]++;
    in((LL)cha[num]*cnt[num]);
}
inline void er(int num){
    num=arr[num];
    dlt((LL)cha[num]*cnt[num]);
    cnt[num]--;
    in((LL)cha[num]*cnt[num]);
}
 
int main(){
    scanf("%d %d", &n, &q);
    int sq=800;
    for(int i=1; i<=n; i++){
        scanf("%d", &arr[i]);
        id.eb(arr[i]);
    }
    svec(id); press(id);
    for(int i=1; i<=n; i++){
        int tmp=lb(id, arr[i])-id.begin()+1;
        cha[tmp]=arr[i];
        arr[i]=tmp;
    }
    for(int i=1; i<=q; i++){
        scanf("%d %d", &qu[i].F, &qu[i].S);
        cmp.eb(mp(qu[i].F/sq, qu[i].S), i);
    }
    for(int i=1; i<=id.size(); i++)in(0ll);
    svec(cmp);
    int l=1, r=0;
    for(auto i:cmp){
        while(qu[i.S].F<l)ins(--l);
        while(qu[i.S].S>r)ins(++r);
        while(qu[i.S].F>l)er(l++);
        while(qu[i.S].S<r)er(r--);
        ans[i.S]=tp();
    }
    for(int i=1; i<=q; i++)printf("%lld\n", ans[i]);
}

Compilation message

historic.cpp: In function 'int main()':
historic.cpp:66:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=1; i<=id.size(); i++)in(0ll);
                  ~^~~~~~~~~~~
historic.cpp:50:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &q);
     ~~~~~^~~~~~~~~~~~~~~~~
historic.cpp:53:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &arr[i]);
         ~~~~~^~~~~~~~~~~~~~~
historic.cpp:63:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &qu[i].F, &qu[i].S);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 7 ms 728 KB Output is correct
18 Correct 23 ms 1328 KB Output is correct
19 Correct 83 ms 4316 KB Output is correct
20 Correct 212 ms 6824 KB Output is correct
21 Correct 361 ms 6876 KB Output is correct
22 Correct 354 ms 7012 KB Output is correct
23 Correct 344 ms 6996 KB Output is correct
24 Correct 361 ms 6996 KB Output is correct
25 Correct 255 ms 13120 KB Output is correct
26 Correct 308 ms 13124 KB Output is correct
27 Correct 282 ms 13128 KB Output is correct
28 Correct 274 ms 13248 KB Output is correct
29 Correct 328 ms 13132 KB Output is correct
30 Correct 341 ms 8540 KB Output is correct
31 Correct 349 ms 6996 KB Output is correct
32 Correct 301 ms 4944 KB Output is correct
33 Correct 317 ms 13076 KB Output is correct
34 Correct 305 ms 13120 KB Output is correct
35 Correct 201 ms 14436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 3 ms 768 KB Output is correct
8 Correct 6 ms 1116 KB Output is correct
9 Correct 13 ms 1528 KB Output is correct
10 Correct 26 ms 896 KB Output is correct
11 Correct 104 ms 5608 KB Output is correct
12 Correct 64 ms 3816 KB Output is correct
13 Correct 77 ms 5608 KB Output is correct
14 Correct 99 ms 5736 KB Output is correct
15 Correct 111 ms 8456 KB Output is correct
16 Correct 68 ms 8036 KB Output is correct
17 Correct 39 ms 4540 KB Output is correct
18 Correct 66 ms 8292 KB Output is correct
19 Correct 65 ms 9444 KB Output is correct
20 Correct 40 ms 6248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 7 ms 728 KB Output is correct
18 Correct 23 ms 1328 KB Output is correct
19 Correct 83 ms 4316 KB Output is correct
20 Correct 212 ms 6824 KB Output is correct
21 Correct 361 ms 6876 KB Output is correct
22 Correct 354 ms 7012 KB Output is correct
23 Correct 344 ms 6996 KB Output is correct
24 Correct 361 ms 6996 KB Output is correct
25 Correct 255 ms 13120 KB Output is correct
26 Correct 308 ms 13124 KB Output is correct
27 Correct 282 ms 13128 KB Output is correct
28 Correct 274 ms 13248 KB Output is correct
29 Correct 328 ms 13132 KB Output is correct
30 Correct 341 ms 8540 KB Output is correct
31 Correct 349 ms 6996 KB Output is correct
32 Correct 301 ms 4944 KB Output is correct
33 Correct 317 ms 13076 KB Output is correct
34 Correct 305 ms 13120 KB Output is correct
35 Correct 201 ms 14436 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 0 ms 384 KB Output is correct
38 Correct 0 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 2 ms 512 KB Output is correct
41 Correct 2 ms 512 KB Output is correct
42 Correct 3 ms 768 KB Output is correct
43 Correct 6 ms 1116 KB Output is correct
44 Correct 13 ms 1528 KB Output is correct
45 Correct 26 ms 896 KB Output is correct
46 Correct 104 ms 5608 KB Output is correct
47 Correct 64 ms 3816 KB Output is correct
48 Correct 77 ms 5608 KB Output is correct
49 Correct 99 ms 5736 KB Output is correct
50 Correct 111 ms 8456 KB Output is correct
51 Correct 68 ms 8036 KB Output is correct
52 Correct 39 ms 4540 KB Output is correct
53 Correct 66 ms 8292 KB Output is correct
54 Correct 65 ms 9444 KB Output is correct
55 Correct 40 ms 6248 KB Output is correct
56 Correct 784 ms 7128 KB Output is correct
57 Correct 1955 ms 13776 KB Output is correct
58 Correct 2667 ms 54212 KB Output is correct
59 Execution timed out 4090 ms 101508 KB Time limit exceeded
60 Halted 0 ms 0 KB -