Блог пользователя lllooolll

Автор lllooolll, история, 5 лет назад, По-английски

The problem


#include <bits/stdc++.h> using namespace std; const int maxn=1000005; long long c[maxn], sum[maxn],n,k,m,N=1000000; vector<pair<int, int> > v[maxn]; int lowbit(int i) { return i&(-i); } void mo(long long pos,long long dt){ int s=(long long)dt*pos; for (;pos<=N;pos+=lowbit(pos)) { c[pos]+=dt; sum[pos]+=s; } } long long find(){ int ta=k,e=0; long long s=0; for (int i=20;i>=0;i--) { if(e+(1<<i)>N) continue; if(c[e+(1<<i)]<ta) { ta-=c[e+(1<<i)]; s+=sum[e+(1<<i)]; e+=(1<<i); } } if (ta && e+1<=N){ s+=(long long)ta*(e+1); } return s; } int main(){ int l,r,c,p; cin>>n>>k>>m; for (int i=1;i<=m;i++) { scanf("%d%d%d%d",&l,&r,&c,&p); v[l].push_back(make_pair(c, p)); v[r+1].push_back(make_pair(-c, p)); } long long sum=0; for (int i=1;i<=n;i++){ for (int j=0;j<v[i].size();j++){ long long pp=v[i][j].first,pos=v[i][j].second; mo(pos,pp); } sum+=find(); } printf("%d",sum); }
  • Проголосовать: нравится
  • -17
  • Проголосовать: не нравится

»
5 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

There is a feature to post your code using syntax highlighting and proper indentation. You should use it to post your code. It's hard to read it this way. And you also haven't provided the link of the problem.