This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
struct P
{
int x,y,z;
bool operator<(const P &a)const{
return x<a.x;
}
};
vector<int> v;
//bitset<4001000> b;
int a,c,i,b,k,n,d,e,m;//dy[15]={0,1,0,-1,-1,1,-1,1},dx[15]={1,0,-1,0,1,1,-1,-1};//
long long l[685130];
int o[335555];
int j[15];
int dx[10]={1,0,-1,0,1,1,-1,-1},dy[10]={0,1,0,-1,1,-1,1,-1},dz[10]={0,0,0,0,1,-1};
long long x,y,mod=1000000007;
long long z[133333];
P u[141111];
stack<int> s;
//set<int> s;
queue<int> q;
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
map<int,int> p;
//list<int> l;
//string r;
//char r[1152][1111];
//deque<int> de;
bool as(P a,P b)
{
if(a.x/d!=b.x/d) return a.x<b.x;
return a.y<b.y;
}
void f(int e,int m)
{
l[i+o[m]-1]+=v[o[m]]*e;
for(int h=(i+o[m]-1)/2;h>0;l[h]=max(l[h*2],l[h*2+1]),h>>=1);
}
int main()
{
v.push_back(0);
scanf("%d %d",&a,&b);
d=sqrt(b);
for(int t=1;t<=a;t++)
{
scanf("%d",&o[t]);
if(!p[o[t]]) p[o[t]]=1,v.push_back(o[t]);
}
sort(v.begin(),v.end());
for(int t=1;t<v.size();p[v[t]]=t,t++);
for(int t=1;t<=a;o[t]=p[o[t]],t++);
for(i=1;i<v.size();i<<=1);
n=1;
for(int t=1;t<=b;u[t].z=t,t++)
scanf("%d %d",&u[t].x,&u[t].y);
sort(u+1,u+1+b,as);
for(int t=1;t<=b;t++)
{
for(;m<u[t].y;f(1,++m));
for(;n>u[t].x;f(1,--n));
for(;m>u[t].y;f(-1,m--));
for(;n<u[t].x;f(-1,n++));
z[u[t].z]=l[1];
}
for(int t=1;t<=b;t++)
printf("%lld\n",z[t]);
}
Compilation message (stderr)
historic.cpp: In function 'int main()':
historic.cpp:63:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int t=1;t<v.size();p[v[t]]=t,t++);
~^~~~~~~~~
historic.cpp:65:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=1;i<v.size();i<<=1);
~^~~~~~~~~
historic.cpp:55:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&a,&b);
~~~~~^~~~~~~~~~~~~~~
historic.cpp:59:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&o[t]);
~~~~~^~~~~~~~~~~~
historic.cpp:68:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&u[t].x,&u[t].y);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |