Submission #259255

#TimeUsernameProblemLanguageResultExecution timeMemory
259255admin역사적 조사 (JOI14_historical)C++14
40 / 100
4090 ms101508 KiB
#pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> #define eb emplace_back #define mp make_pair #define F first #define S second #define all(x) x.begin(), x.end() #define svec(x) sort(x.begin(), x.end()) #define press(x) x.erase(unique(x.begin(), x.end()), x.end()) #define lb(x, v) lower_bound(x.begin(), x.end(), v) using namespace std; typedef long long LL; typedef pair<int, int> pii; vector<pair<pii, int> > cmp; pii qu[100010]; int n, q, arr[100010], cha[100010], cnt[100010]; vector<int> id; LL ans[100010]; priority_queue<LL> pq, del; inline void dlt(LL a){del.push(a);} inline void in(LL a){pq.push(a);} inline LL tp(){ while(!del.empty()){ if(del.top()==pq.top()){ del.pop(); pq.pop(); } else break; } return pq.top(); } inline void ins(int num){ num=arr[num]; dlt((LL)cha[num]*cnt[num]); cnt[num]++; in((LL)cha[num]*cnt[num]); } inline void er(int num){ num=arr[num]; dlt((LL)cha[num]*cnt[num]); cnt[num]--; in((LL)cha[num]*cnt[num]); } int main(){ scanf("%d %d", &n, &q); int sq=800; for(int i=1; i<=n; i++){ scanf("%d", &arr[i]); id.eb(arr[i]); } svec(id); press(id); for(int i=1; i<=n; i++){ int tmp=lb(id, arr[i])-id.begin()+1; cha[tmp]=arr[i]; arr[i]=tmp; } for(int i=1; i<=q; i++){ scanf("%d %d", &qu[i].F, &qu[i].S); cmp.eb(mp(qu[i].F/sq, qu[i].S), i); } for(int i=1; i<=id.size(); i++)in(0ll); svec(cmp); int l=1, r=0; for(auto i:cmp){ while(qu[i.S].F<l)ins(--l); while(qu[i.S].S>r)ins(++r); while(qu[i.S].F>l)er(l++); while(qu[i.S].S<r)er(r--); ans[i.S]=tp(); } for(int i=1; i<=q; i++)printf("%lld\n", ans[i]); }

Compilation message (stderr)

historic.cpp: In function 'int main()':
historic.cpp:66:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=1; i<=id.size(); i++)in(0ll);
                  ~^~~~~~~~~~~
historic.cpp:50:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &q);
     ~~~~~^~~~~~~~~~~~~~~~~
historic.cpp:53:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &arr[i]);
         ~~~~~^~~~~~~~~~~~~~~
historic.cpp:63:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &qu[i].F, &qu[i].S);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...