Submission #259335

# Submission time Handle Problem Language Result Execution time Memory
259335 2020-08-07T15:41:45 Z 최은수(#5042) 역사적 조사 (JOI14_historical) C++17
100 / 100
2417 ms 12004 KB
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#define ep emplace
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const int inf=1e9+7;
const ll INF=1e18+7;
const int bk=404;
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,q;
    cin>>n>>q;
    vector<int>v(n),sv;
    for(int&t:v)
        cin>>t,sv.eb(t);
    sort(all(sv));
    sv.erase(unique(all(sv)),sv.end());
    v.insert(v.begin(),v[0]);
    for(int&t:v)
        t=lower_bound(all(sv),t)-sv.begin();
    vector<vector<pair<pi,int> > >qv(500);
    for(int i=0;i<q;i++)
    {
        int s,e;
        cin>>s>>e;
        qv[s/bk].eb(pi(s,e),i);
    }
    vector<ll>ans(q);
    for(auto&qvt:qv)
    {
        if(qvt.empty())
            continue;
        sort(all(qvt),[](const pair<pi,int>&x,const pair<pi,int>&y)
        {
            return x.fi.se<y.fi.se;
        });
        int cl=qvt[0].fi.fi;
        int cr=qvt[0].fi.fi-1;
        vector<ll>cnt((int)sv.size(),0);
        priority_queue<ll>pq,del;
        pq.ep(0);
        for(auto&t:qvt)
        {
            int l=t.fi.fi;
            int r=t.fi.se;
            while(cl<l)
            {
                if(cnt[v[cl]]!=0)
                    del.ep(cnt[v[cl]]);
                cnt[v[cl]]-=sv[v[cl]];
                if(cnt[v[cl]]!=0)
                    pq.ep(cnt[v[cl]]);
                cl++;
            }
            while(cl>l)
            {
                cl--;
                if(cnt[v[cl]]!=0)
                    del.ep(cnt[v[cl]]);
                cnt[v[cl]]+=sv[v[cl]];
                if(cnt[v[cl]]!=0)
                    pq.ep(cnt[v[cl]]);
            }
            while(cr<r)
            {
                cr++;
                if(cnt[v[cr]]!=0)
                    del.ep(cnt[v[cr]]);
                cnt[v[cr]]+=sv[v[cr]];
                if(cnt[v[cr]]!=0)
                    pq.ep(cnt[v[cr]]);
            }
            while(cr>r)
            {
                if(cnt[v[cr]]!=0)
                    del.ep(cnt[v[cr]]);
                cnt[v[cr]]-=sv[v[cr]];
                if(cnt[v[cr]]!=0)
                    pq.ep(cnt[v[cr]]);
                cr--;
            }
            while(!del.empty()&&pq.top()==del.top())
                pq.pop(),del.pop();
            ans[t.se]=pq.top();
        }
    }
    for(int i=0;i<q;i++)
        cout<<ans[i]<<'\n';
    cout.flush();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 7 ms 640 KB Output is correct
18 Correct 11 ms 1324 KB Output is correct
19 Correct 16 ms 2124 KB Output is correct
20 Correct 30 ms 2836 KB Output is correct
21 Correct 47 ms 3388 KB Output is correct
22 Correct 45 ms 3036 KB Output is correct
23 Correct 58 ms 3352 KB Output is correct
24 Correct 46 ms 3440 KB Output is correct
25 Correct 33 ms 3388 KB Output is correct
26 Correct 33 ms 3236 KB Output is correct
27 Correct 36 ms 3356 KB Output is correct
28 Correct 46 ms 3020 KB Output is correct
29 Correct 36 ms 3348 KB Output is correct
30 Correct 36 ms 3388 KB Output is correct
31 Correct 50 ms 3084 KB Output is correct
32 Correct 71 ms 2964 KB Output is correct
33 Correct 36 ms 3056 KB Output is correct
34 Correct 33 ms 3204 KB Output is correct
35 Correct 34 ms 2996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 5 ms 640 KB Output is correct
9 Correct 12 ms 1024 KB Output is correct
10 Correct 16 ms 1408 KB Output is correct
11 Correct 71 ms 5612 KB Output is correct
12 Correct 52 ms 2608 KB Output is correct
13 Correct 55 ms 3108 KB Output is correct
14 Correct 73 ms 4712 KB Output is correct
15 Correct 106 ms 7128 KB Output is correct
16 Correct 382 ms 5592 KB Output is correct
17 Correct 347 ms 5048 KB Output is correct
18 Correct 355 ms 5376 KB Output is correct
19 Correct 200 ms 6888 KB Output is correct
20 Correct 226 ms 5332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 7 ms 640 KB Output is correct
18 Correct 11 ms 1324 KB Output is correct
19 Correct 16 ms 2124 KB Output is correct
20 Correct 30 ms 2836 KB Output is correct
21 Correct 47 ms 3388 KB Output is correct
22 Correct 45 ms 3036 KB Output is correct
23 Correct 58 ms 3352 KB Output is correct
24 Correct 46 ms 3440 KB Output is correct
25 Correct 33 ms 3388 KB Output is correct
26 Correct 33 ms 3236 KB Output is correct
27 Correct 36 ms 3356 KB Output is correct
28 Correct 46 ms 3020 KB Output is correct
29 Correct 36 ms 3348 KB Output is correct
30 Correct 36 ms 3388 KB Output is correct
31 Correct 50 ms 3084 KB Output is correct
32 Correct 71 ms 2964 KB Output is correct
33 Correct 36 ms 3056 KB Output is correct
34 Correct 33 ms 3204 KB Output is correct
35 Correct 34 ms 2996 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 1 ms 384 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 2 ms 512 KB Output is correct
41 Correct 2 ms 384 KB Output is correct
42 Correct 3 ms 512 KB Output is correct
43 Correct 5 ms 640 KB Output is correct
44 Correct 12 ms 1024 KB Output is correct
45 Correct 16 ms 1408 KB Output is correct
46 Correct 71 ms 5612 KB Output is correct
47 Correct 52 ms 2608 KB Output is correct
48 Correct 55 ms 3108 KB Output is correct
49 Correct 73 ms 4712 KB Output is correct
50 Correct 106 ms 7128 KB Output is correct
51 Correct 382 ms 5592 KB Output is correct
52 Correct 347 ms 5048 KB Output is correct
53 Correct 355 ms 5376 KB Output is correct
54 Correct 200 ms 6888 KB Output is correct
55 Correct 226 ms 5332 KB Output is correct
56 Correct 104 ms 3900 KB Output is correct
57 Correct 165 ms 4148 KB Output is correct
58 Correct 279 ms 4720 KB Output is correct
59 Correct 319 ms 6452 KB Output is correct
60 Correct 420 ms 7740 KB Output is correct
61 Correct 612 ms 8944 KB Output is correct
62 Correct 788 ms 9824 KB Output is correct
63 Correct 1033 ms 10524 KB Output is correct
64 Correct 1432 ms 11268 KB Output is correct
65 Correct 2362 ms 10232 KB Output is correct
66 Correct 1612 ms 11548 KB Output is correct
67 Correct 1344 ms 11748 KB Output is correct
68 Correct 1344 ms 11608 KB Output is correct
69 Correct 1256 ms 11796 KB Output is correct
70 Correct 1184 ms 11320 KB Output is correct
71 Correct 1207 ms 11516 KB Output is correct
72 Correct 1233 ms 11700 KB Output is correct
73 Correct 1272 ms 11748 KB Output is correct
74 Correct 1265 ms 11832 KB Output is correct
75 Correct 1303 ms 11760 KB Output is correct
76 Correct 1295 ms 12004 KB Output is correct
77 Correct 1296 ms 11584 KB Output is correct
78 Correct 1278 ms 11756 KB Output is correct
79 Correct 1292 ms 11624 KB Output is correct
80 Correct 2417 ms 10968 KB Output is correct