Submission #486376

# Submission time Handle Problem Language Result Execution time Memory
486376 2021-11-11T13:16:03 Z leinad2 역사적 조사 (JOI14_historical) C++17
40 / 100
4000 ms 6640 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], seg[400010];
struct query
{
    int i, l, r;
};
vector<query>Q;
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 update(int id, int s, int e, int x, long long v)
{
    if(e<x||x<s)return;
    if(s==e)
    {
        seg[id]=v;
        return;
    }
    int m=s+e>>1;
    update(id*2, s, m, x, v);update(id*2+1, m+1, e, x, v);
    seg[id]=max(seg[id*2], seg[id*2+1]);
}
void add(int i)
{
    cnt[A[i]]++;
    update(1, 1, n, A[i], 1LL*cnt[A[i]]*inv[A[i]]);
}
void del(int i)
{
    cnt[A[i]]--;
    update(1, 1, n, A[i], 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=Q[0].l;i<=Q[0].r;i++)add(i);
    ans[Q[0].i]=seg[1];
    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]=seg[1];
    }
    for(i=0;i++<q;)printf("%lld\n", ans[i]);
}

Compilation message

historic.cpp: In function 'void update(int, int, int, int, long long int)':
historic.cpp:24:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   24 |     int m=s+e>>1;
      |           ~^~
historic.cpp: At global scope:
historic.cpp:38:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   38 | main()
      | ^~~~
historic.cpp: In function 'int main()':
historic.cpp:40:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |     for(scanf("%d %d", &n, &q);i++<n;)
      |         ~~~~~^~~~~~~~~~~~~~~~~
historic.cpp:42:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |         scanf("%d", &A[i]);
      |         ~~~~~^~~~~~~~~~~~~
historic.cpp:56:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |         scanf("%d %d", &a, &b);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 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 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 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 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 3 ms 344 KB Output is correct
19 Correct 13 ms 412 KB Output is correct
20 Correct 29 ms 472 KB Output is correct
21 Correct 58 ms 588 KB Output is correct
22 Correct 60 ms 588 KB Output is correct
23 Correct 53 ms 592 KB Output is correct
24 Correct 53 ms 592 KB Output is correct
25 Correct 59 ms 588 KB Output is correct
26 Correct 59 ms 612 KB Output is correct
27 Correct 63 ms 612 KB Output is correct
28 Correct 86 ms 588 KB Output is correct
29 Correct 72 ms 588 KB Output is correct
30 Correct 59 ms 612 KB Output is correct
31 Correct 52 ms 580 KB Output is correct
32 Correct 51 ms 584 KB Output is correct
33 Correct 61 ms 708 KB Output is correct
34 Correct 75 ms 636 KB Output is correct
35 Correct 76 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 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 3 ms 332 KB Output is correct
8 Correct 7 ms 588 KB Output is correct
9 Correct 15 ms 844 KB Output is correct
10 Correct 20 ms 840 KB Output is correct
11 Correct 92 ms 3700 KB Output is correct
12 Correct 62 ms 1224 KB Output is correct
13 Correct 95 ms 2340 KB Output is correct
14 Correct 93 ms 4012 KB Output is correct
15 Correct 121 ms 5940 KB Output is correct
16 Correct 88 ms 5696 KB Output is correct
17 Correct 53 ms 2252 KB Output is correct
18 Correct 105 ms 3628 KB Output is correct
19 Correct 98 ms 6640 KB Output is correct
20 Correct 48 ms 4848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 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 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 3 ms 344 KB Output is correct
19 Correct 13 ms 412 KB Output is correct
20 Correct 29 ms 472 KB Output is correct
21 Correct 58 ms 588 KB Output is correct
22 Correct 60 ms 588 KB Output is correct
23 Correct 53 ms 592 KB Output is correct
24 Correct 53 ms 592 KB Output is correct
25 Correct 59 ms 588 KB Output is correct
26 Correct 59 ms 612 KB Output is correct
27 Correct 63 ms 612 KB Output is correct
28 Correct 86 ms 588 KB Output is correct
29 Correct 72 ms 588 KB Output is correct
30 Correct 59 ms 612 KB Output is correct
31 Correct 52 ms 580 KB Output is correct
32 Correct 51 ms 584 KB Output is correct
33 Correct 61 ms 708 KB Output is correct
34 Correct 75 ms 636 KB Output is correct
35 Correct 76 ms 724 KB Output is correct
36 Correct 0 ms 204 KB Output is correct
37 Correct 0 ms 332 KB Output is correct
38 Correct 0 ms 332 KB Output is correct
39 Correct 1 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 3 ms 332 KB Output is correct
43 Correct 7 ms 588 KB Output is correct
44 Correct 15 ms 844 KB Output is correct
45 Correct 20 ms 840 KB Output is correct
46 Correct 92 ms 3700 KB Output is correct
47 Correct 62 ms 1224 KB Output is correct
48 Correct 95 ms 2340 KB Output is correct
49 Correct 93 ms 4012 KB Output is correct
50 Correct 121 ms 5940 KB Output is correct
51 Correct 88 ms 5696 KB Output is correct
52 Correct 53 ms 2252 KB Output is correct
53 Correct 105 ms 3628 KB Output is correct
54 Correct 98 ms 6640 KB Output is correct
55 Correct 48 ms 4848 KB Output is correct
56 Correct 161 ms 828 KB Output is correct
57 Correct 565 ms 1184 KB Output is correct
58 Correct 1059 ms 1548 KB Output is correct
59 Correct 1849 ms 2364 KB Output is correct
60 Correct 2664 ms 2676 KB Output is correct
61 Correct 3114 ms 4096 KB Output is correct
62 Correct 3643 ms 4868 KB Output is correct
63 Execution timed out 4056 ms 4592 KB Time limit exceeded
64 Halted 0 ms 0 KB -