結果

問題 No.877 Range ReLU Query
ユーザー mortalmortal
提出日時 2021-08-03 03:07:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 106 ms / 2,000 ms
コード長 1,870 bytes
コンパイル時間 1,750 ms
コンパイル使用メモリ 169,344 KB
実行使用メモリ 11,432 KB
最終ジャッジ日時 2024-04-25 22:30:56
合計ジャッジ時間 4,259 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 3 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 99 ms
10,352 KB
testcase_12 AC 90 ms
9,484 KB
testcase_13 AC 72 ms
8,576 KB
testcase_14 AC 74 ms
8,420 KB
testcase_15 AC 106 ms
11,096 KB
testcase_16 AC 101 ms
10,960 KB
testcase_17 AC 102 ms
11,040 KB
testcase_18 AC 104 ms
10,868 KB
testcase_19 AC 99 ms
11,384 KB
testcase_20 AC 101 ms
11,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

#define ll long long int
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
//note x>0
struct node
{
   ll val;
   int pos;
   int l;
   int r;
};
bool comp(node a,node b)
{
    if(a.val==b.val)
    {
        return a.l>b.l;
    }
    else
    {
        return a.val<b.val;
    }
}
const int N=100005;
ll bit[N];
int n;
void upd(int x,ll val){
   while(x<=n)
   {
      bit[x]+=val;
      x+=(x & (-x));
   }
}
ll pref(ll x)
{
   ll ans=0;
   while(x>0){
      ans=ans+bit[x];
      x-=(x & (-x));
   }
   return ans;
}
ll rsum(int l,int r)
{
   return pref(r)-pref(l-1);
}


ll bit1[N];

void upd1(int x,ll val){
   while(x<=n)
   {
      bit1[x]+=val;
      x+=(x & (-x));
   }
}
ll pref1(ll x)
{
   ll ans=0;
   while(x>0){
      ans=ans+bit1[x];
      x-=(x & (-x));
   }
   return ans;
}
ll rsum1(int l,int r)
{
   return pref1(r)-pref1(l-1);
}

  
int main()
{
   fast;
   int i,j,q;
   cin>>n>>q;
   node a[n+q];
   ll p[n+1]={0};
   for(i=0;i<n;i++)
   {
      ll x;
      cin>>x;
      p[i+1]=p[i]+x;
      a[i].val=x;
      a[i].pos=-1;
      a[i].l=0;
      a[i].r=i+1;

   }
   for(i=0;i<q;i++)
   {
      int t;
      cin>>t;
      ll l,r,x;
      cin>>l>>r>>x;
      a[i+n].val=x;
      a[i+n].pos=i;
      a[i+n].l=l;
      a[i+n].r=r;

   }
   sort(a,a+n+q,comp);
   ll ans[q];
   for(i=0;i<n+q;i++)
   {
      if(a[i].pos==-1)
      {
         upd(a[i].r,1);
         upd1(a[i].r,a[i].val);
      }
      else
      {
         
         ll x=a[i].r-a[i].l+1;
         x=x-rsum(a[i].l,a[i].r);
         
         ll y=p[a[i].r]-p[a[i].l-1];
         y=y-rsum1(a[i].l,a[i].r);
         

         ans[a[i].pos]=y-x*a[i].val;
      }
   }
   for(i=0;i<q;i++)
      cout<<ans[i]<<"\n";


   


   
   
}
0