# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
24872 | 2017-06-16T14:23:31 Z | evenharder | 역사적 조사 (JOI14_historical) | C++11 | 353 ms | 2444 KB |
#include <cstdio> #include <set> #include <map> #include <vector> #include <algorithm> #include <utility> #include <cmath> struct query{ int l,r,n; long long int ans; query(int l=0, int r=0, int n=0) : l(l), r(r), n(n) {ans=0LL;} }; std::map<int, long long int> m; // amount std::multiset<long long int, std::greater<long long int> > s; std::vector<query> vq; const int MAX_N=100000; int x[MAX_N+1]; int n,q; void calc() { int sq=(int)(ceil(sqrt(n+1))); std::sort(vq.begin(), vq.end(), [&] (query A, query B) { return A.l/sq == B.l/sq ? A.r < B.r : A.l < B.l; }); int l=1; int r=0; for(int i=0;i<n;i++) s.insert(0); for(int i=0;i<q;i++) { printf("q %d %d\n",vq[i].l,vq[i].r); while(r<vq[i].r) { r++; long long int prev = m[x[r]] * x[r]; s.erase(prev); m[x[r]]++; s.insert(prev+x[r]); } while(r>vq[i].r) { long long int prev = m[x[r]] * x[r]; s.erase(prev); m[x[r]]--; s.insert(prev-x[r]); r--; } while(l<vq[i].l) { long long int prev = m[x[l]] * x[l]; s.erase(prev); m[x[l]]--; s.insert(prev-x[l]); l++; } while(l>vq[i].l) { l--; long long int prev = m[x[l]] * x[l]; s.erase(prev); m[x[l]]++; s.insert(prev+x[l]); } vq[i].ans=*s.begin(); } std::sort(vq.begin(), vq.end(), [&] (query A, query B) { return A.n < B.n; }); for(int i=0;i<q;i++) printf("%lld\n", vq[i].ans); } int main() { scanf("%d%d",&n,&q); for(int i=1;i<=n;i++) { scanf("%d",&x[i]); } for(int i=0;i<q;i++) { static int l,r; scanf("%d%d",&l,&r); vq.push_back(query(l,r,i)); } calc(); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 1584 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 1584 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 1584 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 353 ms | 2444 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |