답안 #486370

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
486370 2021-11-11T12:58:28 Z leinad2 역사적 조사 (JOI14_historical) C++17
40 / 100
4000 ms 10800 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 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 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 1 ms 204 KB Output is correct
11 Correct 1 ms 332 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 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 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 1 ms 204 KB Output is correct
11 Correct 1 ms 332 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 332 KB Output is correct
17 Correct 3 ms 332 KB Output is correct
18 Correct 5 ms 332 KB Output is correct
19 Correct 13 ms 416 KB Output is correct
20 Correct 37 ms 496 KB Output is correct
21 Correct 64 ms 624 KB Output is correct
22 Correct 70 ms 588 KB Output is correct
23 Correct 53 ms 680 KB Output is correct
24 Correct 52 ms 620 KB Output is correct
25 Correct 90 ms 572 KB Output is correct
26 Correct 95 ms 708 KB Output is correct
27 Correct 89 ms 660 KB Output is correct
28 Correct 92 ms 684 KB Output is correct
29 Correct 90 ms 644 KB Output is correct
30 Correct 86 ms 648 KB Output is correct
31 Correct 57 ms 588 KB Output is correct
32 Correct 30 ms 716 KB Output is correct
33 Correct 82 ms 656 KB Output is correct
34 Correct 89 ms 660 KB Output is correct
35 Correct 90 ms 668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 2 ms 316 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 5 ms 460 KB Output is correct
8 Correct 9 ms 716 KB Output is correct
9 Correct 21 ms 1156 KB Output is correct
10 Correct 10 ms 1156 KB Output is correct
11 Correct 80 ms 5172 KB Output is correct
12 Correct 46 ms 2008 KB Output is correct
13 Correct 76 ms 3148 KB Output is correct
14 Correct 112 ms 6200 KB Output is correct
15 Correct 143 ms 9144 KB Output is correct
16 Correct 129 ms 9520 KB Output is correct
17 Correct 45 ms 2836 KB Output is correct
18 Correct 73 ms 5160 KB Output is correct
19 Correct 131 ms 10800 KB Output is correct
20 Correct 83 ms 8252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 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 1 ms 204 KB Output is correct
11 Correct 1 ms 332 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 332 KB Output is correct
17 Correct 3 ms 332 KB Output is correct
18 Correct 5 ms 332 KB Output is correct
19 Correct 13 ms 416 KB Output is correct
20 Correct 37 ms 496 KB Output is correct
21 Correct 64 ms 624 KB Output is correct
22 Correct 70 ms 588 KB Output is correct
23 Correct 53 ms 680 KB Output is correct
24 Correct 52 ms 620 KB Output is correct
25 Correct 90 ms 572 KB Output is correct
26 Correct 95 ms 708 KB Output is correct
27 Correct 89 ms 660 KB Output is correct
28 Correct 92 ms 684 KB Output is correct
29 Correct 90 ms 644 KB Output is correct
30 Correct 86 ms 648 KB Output is correct
31 Correct 57 ms 588 KB Output is correct
32 Correct 30 ms 716 KB Output is correct
33 Correct 82 ms 656 KB Output is correct
34 Correct 89 ms 660 KB Output is correct
35 Correct 90 ms 668 KB Output is correct
36 Correct 0 ms 204 KB Output is correct
37 Correct 1 ms 204 KB Output is correct
38 Correct 0 ms 204 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 2 ms 316 KB Output is correct
41 Correct 2 ms 332 KB Output is correct
42 Correct 5 ms 460 KB Output is correct
43 Correct 9 ms 716 KB Output is correct
44 Correct 21 ms 1156 KB Output is correct
45 Correct 10 ms 1156 KB Output is correct
46 Correct 80 ms 5172 KB Output is correct
47 Correct 46 ms 2008 KB Output is correct
48 Correct 76 ms 3148 KB Output is correct
49 Correct 112 ms 6200 KB Output is correct
50 Correct 143 ms 9144 KB Output is correct
51 Correct 129 ms 9520 KB Output is correct
52 Correct 45 ms 2836 KB Output is correct
53 Correct 73 ms 5160 KB Output is correct
54 Correct 131 ms 10800 KB Output is correct
55 Correct 83 ms 8252 KB Output is correct
56 Correct 157 ms 948 KB Output is correct
57 Correct 601 ms 1468 KB Output is correct
58 Correct 1520 ms 2208 KB Output is correct
59 Correct 2861 ms 3080 KB Output is correct
60 Execution timed out 4070 ms 3380 KB Time limit exceeded
61 Halted 0 ms 0 KB -