답안 #486371

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
486371 2021-11-11T13:05:06 Z leinad2 역사적 조사 (JOI14_historical) C++17
40 / 100
4000 ms 8820 KB
#include<bits/stdc++.h>
using namespace std;
int n, q, i, j, k, a, b, B, inv[100010], A[100010], cnt[100010];
vector<int>comp;
long long ans[100010];
struct query
{
    int i, l, r;
};
vector<query>Q;
multiset<long long>s;
bool cmp(query a, query b)
{
    if(a.l/B==b.l/B)return a.r<b.r;
    else return a.l/B<b.l/B;
}
void add(int i)
{
    s.erase(s.find(1LL*cnt[A[i]]*inv[A[i]]));
    cnt[A[i]]++;
    s.insert(1LL*cnt[A[i]]*inv[A[i]]);
}
void del(int i)
{
    s.erase(s.find(1LL*cnt[A[i]]*inv[A[i]]));
    cnt[A[i]]--;
    s.insert(1LL*cnt[A[i]]*inv[A[i]]);
}
main()
{
    for(scanf("%d %d", &n, &q);i++<n;)
    {
        scanf("%d", &A[i]);
        comp.push_back(A[i]);
    }
    sort(comp.begin(), comp.end());
    comp.erase(unique(comp.begin(), comp.end()), comp.end());
    for(i=0;i++<n;)
    {
        a=lower_bound(comp.begin(), comp.end(), A[i])-comp.begin()+1;
        inv[a]=A[i];
        A[i]=a;
    }
    B=(int)sqrt(n);
    for(i=0;i++<q;)
    {
        scanf("%d %d", &a, &b);
        Q.push_back({i, a, b});
    }
    sort(Q.begin(), Q.end(), cmp);
    for(i=0;i<comp.size();i++)s.insert(0);
    for(i=Q[0].l;i<=Q[0].r;i++)add(i);
    ans[Q[0].i]=*s.rbegin();
    for(i=1;i<q;i++)
    {
        if(Q[i].l<Q[i-1].l)for(j=Q[i-1].l-1;j>=Q[i].l;j--)add(j);
        else for(j=Q[i-1].l;j<Q[i].l;j++)del(j);
        if(Q[i].r>Q[i-1].r)for(j=Q[i-1].r+1;j<=Q[i].r;j++)add(j);
        else for(j=Q[i-1].r;j>Q[i].r;j--)del(j);
        ans[Q[i].i]=*s.rbegin();
    }
    for(i=0;i++<q;)printf("%lld\n", ans[i]);
}

Compilation message

historic.cpp:29:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   29 | main()
      | ^~~~
historic.cpp: In function 'int main()':
historic.cpp:51:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |     for(i=0;i<comp.size();i++)s.insert(0);
      |             ~^~~~~~~~~~~~
historic.cpp:31:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |     for(scanf("%d %d", &n, &q);i++<n;)
      |         ~~~~~^~~~~~~~~~~~~~~~~
historic.cpp:33:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |         scanf("%d", &A[i]);
      |         ~~~~~^~~~~~~~~~~~~
historic.cpp:47:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |         scanf("%d %d", &a, &b);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 5 ms 332 KB Output is correct
19 Correct 12 ms 388 KB Output is correct
20 Correct 37 ms 444 KB Output is correct
21 Correct 68 ms 460 KB Output is correct
22 Correct 71 ms 540 KB Output is correct
23 Correct 51 ms 544 KB Output is correct
24 Correct 53 ms 548 KB Output is correct
25 Correct 92 ms 580 KB Output is correct
26 Correct 91 ms 564 KB Output is correct
27 Correct 90 ms 568 KB Output is correct
28 Correct 88 ms 564 KB Output is correct
29 Correct 80 ms 560 KB Output is correct
30 Correct 84 ms 552 KB Output is correct
31 Correct 54 ms 580 KB Output is correct
32 Correct 27 ms 560 KB Output is correct
33 Correct 83 ms 544 KB Output is correct
34 Correct 91 ms 556 KB Output is correct
35 Correct 93 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 4 ms 332 KB Output is correct
8 Correct 8 ms 492 KB Output is correct
9 Correct 17 ms 836 KB Output is correct
10 Correct 9 ms 784 KB Output is correct
11 Correct 77 ms 3648 KB Output is correct
12 Correct 47 ms 1224 KB Output is correct
13 Correct 74 ms 2108 KB Output is correct
14 Correct 114 ms 4736 KB Output is correct
15 Correct 140 ms 7060 KB Output is correct
16 Correct 128 ms 8056 KB Output is correct
17 Correct 43 ms 2124 KB Output is correct
18 Correct 71 ms 3588 KB Output is correct
19 Correct 125 ms 8820 KB Output is correct
20 Correct 77 ms 7124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 5 ms 332 KB Output is correct
19 Correct 12 ms 388 KB Output is correct
20 Correct 37 ms 444 KB Output is correct
21 Correct 68 ms 460 KB Output is correct
22 Correct 71 ms 540 KB Output is correct
23 Correct 51 ms 544 KB Output is correct
24 Correct 53 ms 548 KB Output is correct
25 Correct 92 ms 580 KB Output is correct
26 Correct 91 ms 564 KB Output is correct
27 Correct 90 ms 568 KB Output is correct
28 Correct 88 ms 564 KB Output is correct
29 Correct 80 ms 560 KB Output is correct
30 Correct 84 ms 552 KB Output is correct
31 Correct 54 ms 580 KB Output is correct
32 Correct 27 ms 560 KB Output is correct
33 Correct 83 ms 544 KB Output is correct
34 Correct 91 ms 556 KB Output is correct
35 Correct 93 ms 588 KB Output is correct
36 Correct 1 ms 204 KB Output is correct
37 Correct 1 ms 204 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 2 ms 332 KB Output is correct
40 Correct 2 ms 332 KB Output is correct
41 Correct 2 ms 332 KB Output is correct
42 Correct 4 ms 332 KB Output is correct
43 Correct 8 ms 492 KB Output is correct
44 Correct 17 ms 836 KB Output is correct
45 Correct 9 ms 784 KB Output is correct
46 Correct 77 ms 3648 KB Output is correct
47 Correct 47 ms 1224 KB Output is correct
48 Correct 74 ms 2108 KB Output is correct
49 Correct 114 ms 4736 KB Output is correct
50 Correct 140 ms 7060 KB Output is correct
51 Correct 128 ms 8056 KB Output is correct
52 Correct 43 ms 2124 KB Output is correct
53 Correct 71 ms 3588 KB Output is correct
54 Correct 125 ms 8820 KB Output is correct
55 Correct 77 ms 7124 KB Output is correct
56 Correct 161 ms 784 KB Output is correct
57 Correct 614 ms 1120 KB Output is correct
58 Correct 1590 ms 1656 KB Output is correct
59 Correct 2864 ms 2364 KB Output is correct
60 Execution timed out 4077 ms 2508 KB Time limit exceeded
61 Halted 0 ms 0 KB -