답안 #486037

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
486037 2021-11-10T11:47:54 Z urd05 역사적 조사 (JOI14_historical) C++17
40 / 100
4000 ms 14612 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]);
        }
        sort(hubo.begin(),hubo.end());
        hubo.erase(unique(hubo.begin(),hubo.end()),hubo.end());
        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:77:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |         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);
      |         ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2636 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 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 2636 KB Output is correct
9 Correct 2 ms 2636 KB Output is correct
10 Correct 2 ms 2636 KB Output is correct
11 Correct 2 ms 2636 KB Output is correct
12 Correct 3 ms 2636 KB Output is correct
13 Correct 2 ms 2636 KB Output is correct
14 Correct 2 ms 2636 KB Output is correct
15 Correct 2 ms 2636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2636 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 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 2636 KB Output is correct
9 Correct 2 ms 2636 KB Output is correct
10 Correct 2 ms 2636 KB Output is correct
11 Correct 2 ms 2636 KB Output is correct
12 Correct 3 ms 2636 KB Output is correct
13 Correct 2 ms 2636 KB Output is correct
14 Correct 2 ms 2636 KB Output is correct
15 Correct 2 ms 2636 KB Output is correct
16 Correct 2 ms 2636 KB Output is correct
17 Correct 5 ms 2636 KB Output is correct
18 Correct 13 ms 2720 KB Output is correct
19 Correct 34 ms 2776 KB Output is correct
20 Correct 70 ms 2892 KB Output is correct
21 Correct 98 ms 3020 KB Output is correct
22 Correct 112 ms 3028 KB Output is correct
23 Correct 75 ms 3020 KB Output is correct
24 Correct 78 ms 3020 KB Output is correct
25 Correct 108 ms 3088 KB Output is correct
26 Correct 105 ms 3052 KB Output is correct
27 Correct 113 ms 3068 KB Output is correct
28 Correct 108 ms 3052 KB Output is correct
29 Correct 110 ms 3036 KB Output is correct
30 Correct 120 ms 3044 KB Output is correct
31 Correct 76 ms 3020 KB Output is correct
32 Correct 36 ms 3020 KB Output is correct
33 Correct 111 ms 3028 KB Output is correct
34 Correct 106 ms 3088 KB Output is correct
35 Correct 104 ms 3068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2636 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 2892 KB Output is correct
7 Correct 10 ms 3128 KB Output is correct
8 Correct 30 ms 3816 KB Output is correct
9 Correct 101 ms 4832 KB Output is correct
10 Correct 270 ms 6240 KB Output is correct
11 Correct 1363 ms 9828 KB Output is correct
12 Correct 972 ms 9920 KB Output is correct
13 Correct 1666 ms 10268 KB Output is correct
14 Correct 2033 ms 12964 KB Output is correct
15 Correct 1922 ms 13804 KB Output is correct
16 Correct 3604 ms 14612 KB Output is correct
17 Correct 1552 ms 9032 KB Output is correct
18 Correct 2247 ms 9008 KB Output is correct
19 Correct 3998 ms 14580 KB Output is correct
20 Correct 3257 ms 14600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2636 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 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 2636 KB Output is correct
9 Correct 2 ms 2636 KB Output is correct
10 Correct 2 ms 2636 KB Output is correct
11 Correct 2 ms 2636 KB Output is correct
12 Correct 3 ms 2636 KB Output is correct
13 Correct 2 ms 2636 KB Output is correct
14 Correct 2 ms 2636 KB Output is correct
15 Correct 2 ms 2636 KB Output is correct
16 Correct 2 ms 2636 KB Output is correct
17 Correct 5 ms 2636 KB Output is correct
18 Correct 13 ms 2720 KB Output is correct
19 Correct 34 ms 2776 KB Output is correct
20 Correct 70 ms 2892 KB Output is correct
21 Correct 98 ms 3020 KB Output is correct
22 Correct 112 ms 3028 KB Output is correct
23 Correct 75 ms 3020 KB Output is correct
24 Correct 78 ms 3020 KB Output is correct
25 Correct 108 ms 3088 KB Output is correct
26 Correct 105 ms 3052 KB Output is correct
27 Correct 113 ms 3068 KB Output is correct
28 Correct 108 ms 3052 KB Output is correct
29 Correct 110 ms 3036 KB Output is correct
30 Correct 120 ms 3044 KB Output is correct
31 Correct 76 ms 3020 KB Output is correct
32 Correct 36 ms 3020 KB Output is correct
33 Correct 111 ms 3028 KB Output is correct
34 Correct 106 ms 3088 KB Output is correct
35 Correct 104 ms 3068 KB Output is correct
36 Correct 2 ms 2636 KB Output is correct
37 Correct 2 ms 2636 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 2892 KB Output is correct
42 Correct 10 ms 3128 KB Output is correct
43 Correct 30 ms 3816 KB Output is correct
44 Correct 101 ms 4832 KB Output is correct
45 Correct 270 ms 6240 KB Output is correct
46 Correct 1363 ms 9828 KB Output is correct
47 Correct 972 ms 9920 KB Output is correct
48 Correct 1666 ms 10268 KB Output is correct
49 Correct 2033 ms 12964 KB Output is correct
50 Correct 1922 ms 13804 KB Output is correct
51 Correct 3604 ms 14612 KB Output is correct
52 Correct 1552 ms 9032 KB Output is correct
53 Correct 2247 ms 9008 KB Output is correct
54 Correct 3998 ms 14580 KB Output is correct
55 Correct 3257 ms 14600 KB Output is correct
56 Correct 187 ms 3392 KB Output is correct
57 Correct 583 ms 4148 KB Output is correct
58 Correct 899 ms 5492 KB Output is correct
59 Correct 1248 ms 6508 KB Output is correct
60 Correct 1580 ms 7812 KB Output is correct
61 Correct 2179 ms 6444 KB Output is correct
62 Correct 2467 ms 8252 KB Output is correct
63 Correct 1887 ms 9112 KB Output is correct
64 Correct 1742 ms 9016 KB Output is correct
65 Correct 1900 ms 9676 KB Output is correct
66 Correct 2185 ms 9924 KB Output is correct
67 Correct 3828 ms 9960 KB Output is correct
68 Execution timed out 4086 ms 11384 KB Time limit exceeded
69 Halted 0 ms 0 KB -