Submission #486035

# Submission time Handle Problem Language Result Execution time Memory
486035 2021-11-10T11:45:05 Z urd05 역사적 조사 (JOI14_historical) C++17
40 / 100
4000 ms 15756 KB
#include <bits/stdc++.h>
using namespace std;

vector<int> press;
vector<int> vec[100000];
int n,q;
int arr[100000];
const int sq=320;
int save[320][320];
typedef pair<long long,int> P;

long long cal(int x,int l,int r) {
    return press[x]*(upper_bound(vec[x].begin(),vec[x].end(),r)-lower_bound(vec[x].begin(),vec[x].end(),l));
}

int main(void) {
    scanf("%d %d",&n,&q);
    for(int i=0;i<n;i++) {
        scanf("%d",&arr[i]);
        press.push_back(arr[i]);
    }
    sort(press.begin(),press.end());
    press.erase(unique(press.begin(),press.end()),press.end());
    for(int i=0;i<n;i++) {
        arr[i]=lower_bound(press.begin(),press.end(),arr[i])-press.begin();
        vec[arr[i]].push_back(i);
    }
    for(int i=0;i<n;i+=sq) {
        priority_queue<P> pq;
        priority_queue<P> er;
        vector<long long> temp(press.size());
        for(int j=0;j<press.size();j++) {
            pq.push(P(0,j));
            temp[j]=0;
        }
        for(int j=i;j<n;j++) {
            er.push(P(temp[arr[j]],arr[j]));
            temp[arr[j]]+=press[arr[j]];
            pq.push(P(temp[arr[j]],arr[j]));
            while (!er.empty()&&pq.top()==er.top()) {
                pq.pop();
                er.pop();
            }
            if (j%sq==sq-1) {
                save[i/sq][j/sq]=pq.top().second;
            }
        }
    }
    for(int i=0;i<q;i++) {
        int l,r;
        scanf("%d %d",&l,&r);
        l--;
        r--;
        int ll=l;
        int rr=r;
        vector<int> hubo;
        if (l/sq==r/sq) {
            for(int j=l;j<=r;j++) {
                hubo.push_back(arr[j]);
            }
        }
        else {
            while (l%sq!=0) {
                hubo.push_back(arr[l]);
                l++;
            }
            while (r%sq!=sq-1) {
                hubo.push_back(arr[r]);
                r--;
            }
            if (l/sq<=r/sq)
                hubo.push_back(save[l/sq][r/sq]);
        }
        long long ret=0;
        for(int j=0;j<hubo.size();j++) {
            ret=max(ret,cal(hubo[j],ll,rr));
        }
        printf("%lld\n",ret);
    }
}

Compilation message

historic.cpp: In function 'int main()':
historic.cpp:32:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |         for(int j=0;j<press.size();j++) {
      |                     ~^~~~~~~~~~~~~
historic.cpp:75:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |         for(int j=0;j<hubo.size();j++) {
      |                     ~^~~~~~~~~~~~
historic.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     scanf("%d %d",&n,&q);
      |     ~~~~~^~~~~~~~~~~~~~~
historic.cpp:19:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         scanf("%d",&arr[i]);
      |         ~~~~~^~~~~~~~~~~~~~
historic.cpp:51:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |         scanf("%d %d",&l,&r);
      |         ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 3 ms 2636 KB Output is correct
4 Correct 3 ms 2636 KB Output is correct
5 Correct 2 ms 2636 KB Output is correct
6 Correct 2 ms 2636 KB Output is correct
7 Correct 2 ms 2636 KB Output is correct
8 Correct 2 ms 2608 KB Output is correct
9 Correct 2 ms 2636 KB Output is correct
10 Correct 3 ms 2644 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 2 ms 2636 KB Output is correct
13 Correct 2 ms 2636 KB Output is correct
14 Correct 3 ms 2596 KB Output is correct
15 Correct 2 ms 2636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 3 ms 2636 KB Output is correct
4 Correct 3 ms 2636 KB Output is correct
5 Correct 2 ms 2636 KB Output is correct
6 Correct 2 ms 2636 KB Output is correct
7 Correct 2 ms 2636 KB Output is correct
8 Correct 2 ms 2608 KB Output is correct
9 Correct 2 ms 2636 KB Output is correct
10 Correct 3 ms 2644 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 2 ms 2636 KB Output is correct
13 Correct 2 ms 2636 KB Output is correct
14 Correct 3 ms 2596 KB Output is correct
15 Correct 2 ms 2636 KB Output is correct
16 Correct 3 ms 2636 KB Output is correct
17 Correct 4 ms 2636 KB Output is correct
18 Correct 10 ms 2636 KB Output is correct
19 Correct 24 ms 2812 KB Output is correct
20 Correct 54 ms 2896 KB Output is correct
21 Correct 96 ms 3104 KB Output is correct
22 Correct 93 ms 3088 KB Output is correct
23 Correct 102 ms 3076 KB Output is correct
24 Correct 105 ms 3044 KB Output is correct
25 Correct 84 ms 3196 KB Output is correct
26 Correct 82 ms 3204 KB Output is correct
27 Correct 82 ms 3180 KB Output is correct
28 Correct 70 ms 3180 KB Output is correct
29 Correct 69 ms 3148 KB Output is correct
30 Correct 69 ms 3152 KB Output is correct
31 Correct 99 ms 3148 KB Output is correct
32 Correct 74 ms 3112 KB Output is correct
33 Correct 86 ms 3168 KB Output is correct
34 Correct 78 ms 3164 KB Output is correct
35 Correct 57 ms 3196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2648 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 2 ms 2636 KB Output is correct
5 Correct 3 ms 2764 KB Output is correct
6 Correct 4 ms 2896 KB Output is correct
7 Correct 11 ms 3244 KB Output is correct
8 Correct 29 ms 3864 KB Output is correct
9 Correct 111 ms 5084 KB Output is correct
10 Correct 336 ms 6552 KB Output is correct
11 Correct 1821 ms 10756 KB Output is correct
12 Correct 1105 ms 10676 KB Output is correct
13 Correct 1602 ms 11276 KB Output is correct
14 Correct 2112 ms 14088 KB Output is correct
15 Correct 2230 ms 14944 KB Output is correct
16 Correct 3530 ms 15756 KB Output is correct
17 Correct 1751 ms 9556 KB Output is correct
18 Correct 2734 ms 10180 KB Output is correct
19 Correct 3799 ms 15720 KB Output is correct
20 Correct 3477 ms 15712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 3 ms 2636 KB Output is correct
4 Correct 3 ms 2636 KB Output is correct
5 Correct 2 ms 2636 KB Output is correct
6 Correct 2 ms 2636 KB Output is correct
7 Correct 2 ms 2636 KB Output is correct
8 Correct 2 ms 2608 KB Output is correct
9 Correct 2 ms 2636 KB Output is correct
10 Correct 3 ms 2644 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 2 ms 2636 KB Output is correct
13 Correct 2 ms 2636 KB Output is correct
14 Correct 3 ms 2596 KB Output is correct
15 Correct 2 ms 2636 KB Output is correct
16 Correct 3 ms 2636 KB Output is correct
17 Correct 4 ms 2636 KB Output is correct
18 Correct 10 ms 2636 KB Output is correct
19 Correct 24 ms 2812 KB Output is correct
20 Correct 54 ms 2896 KB Output is correct
21 Correct 96 ms 3104 KB Output is correct
22 Correct 93 ms 3088 KB Output is correct
23 Correct 102 ms 3076 KB Output is correct
24 Correct 105 ms 3044 KB Output is correct
25 Correct 84 ms 3196 KB Output is correct
26 Correct 82 ms 3204 KB Output is correct
27 Correct 82 ms 3180 KB Output is correct
28 Correct 70 ms 3180 KB Output is correct
29 Correct 69 ms 3148 KB Output is correct
30 Correct 69 ms 3152 KB Output is correct
31 Correct 99 ms 3148 KB Output is correct
32 Correct 74 ms 3112 KB Output is correct
33 Correct 86 ms 3168 KB Output is correct
34 Correct 78 ms 3164 KB Output is correct
35 Correct 57 ms 3196 KB Output is correct
36 Correct 2 ms 2636 KB Output is correct
37 Correct 2 ms 2648 KB Output is correct
38 Correct 2 ms 2636 KB Output is correct
39 Correct 2 ms 2636 KB Output is correct
40 Correct 3 ms 2764 KB Output is correct
41 Correct 4 ms 2896 KB Output is correct
42 Correct 11 ms 3244 KB Output is correct
43 Correct 29 ms 3864 KB Output is correct
44 Correct 111 ms 5084 KB Output is correct
45 Correct 336 ms 6552 KB Output is correct
46 Correct 1821 ms 10756 KB Output is correct
47 Correct 1105 ms 10676 KB Output is correct
48 Correct 1602 ms 11276 KB Output is correct
49 Correct 2112 ms 14088 KB Output is correct
50 Correct 2230 ms 14944 KB Output is correct
51 Correct 3530 ms 15756 KB Output is correct
52 Correct 1751 ms 9556 KB Output is correct
53 Correct 2734 ms 10180 KB Output is correct
54 Correct 3799 ms 15720 KB Output is correct
55 Correct 3477 ms 15712 KB Output is correct
56 Correct 284 ms 3520 KB Output is correct
57 Correct 451 ms 4512 KB Output is correct
58 Correct 648 ms 5848 KB Output is correct
59 Correct 893 ms 7024 KB Output is correct
60 Correct 1069 ms 8660 KB Output is correct
61 Correct 1667 ms 7448 KB Output is correct
62 Correct 2327 ms 9660 KB Output is correct
63 Correct 2878 ms 10064 KB Output is correct
64 Correct 2959 ms 10804 KB Output is correct
65 Correct 2870 ms 10400 KB Output is correct
66 Correct 3434 ms 10792 KB Output is correct
67 Execution timed out 4046 ms 11044 KB Time limit exceeded
68 Halted 0 ms 0 KB -