結果

問題 No.2065 Sum of Min
ユーザー akuaakua
提出日時 2022-09-04 17:34:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,604 bytes
コンパイル時間 3,700 ms
コンパイル使用メモリ 188,800 KB
実行使用メモリ 6,688 KB
最終ジャッジ日時 2024-04-29 17:49:00
合計ジャッジ時間 25,592 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 870 ms
6,556 KB
testcase_05 AC 1,529 ms
6,556 KB
testcase_06 AC 1,372 ms
6,684 KB
testcase_07 AC 1,074 ms
6,560 KB
testcase_08 AC 877 ms
6,560 KB
testcase_09 AC 185 ms
6,684 KB
testcase_10 TLE -
testcase_11 TLE -
testcase_12 AC 926 ms
6,688 KB
testcase_13 AC 922 ms
6,556 KB
testcase_14 AC 923 ms
6,680 KB
testcase_15 AC 917 ms
6,684 KB
testcase_16 AC 927 ms
6,596 KB
testcase_17 AC 930 ms
6,684 KB
testcase_18 AC 919 ms
6,684 KB
testcase_19 AC 919 ms
6,684 KB
testcase_20 AC 919 ms
6,680 KB
testcase_21 AC 934 ms
6,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/all>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;  
using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
typedef long long ll;
typedef unsigned long long ull;
const ll inf=1e18;  
using graph = vector<vector<int> > ;
using P= pair<ll,ll>;  
using vi=vector<int>;
using vvi=vector<vi>;
using vll=vector<ll>; 
using vvll=vector<vll>;
using vp=vector<P>;
using vpp=vector<vp>;
//string T="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
//string S="abcdefghijklmnopqrstuvwxyz";
//g++ main.cpp -std=c++14 -I .  
//cout <<setprecision(20);
//cout << fixed << setprecision(10);
//cin.tie(0); ios::sync_with_stdio(false);
const double PI = acos(-1);



int main(){cin.tie(0); ios::sync_with_stdio(false);
  int n,q; cin >> n >> q;
  vector<ll>  a(n);rep(i,n)cin >> a[i];
  int x=sqrt(n)+1;
  int si=n/x+2;
  vvi g(si);
  vvll sum(si,vll(x+1));
  rep(i,n)g[i/x].push_back(a[i]);
  rep(i,si)sort(g[i].begin(),g[i].end());
  rep(i,si)rep(j,g[i].size())sum[i][j+1]=sum[i][j]+g[i][j];
  vll anss;
  auto f2=[&](int i,ll k){
     int index=upper_bound(g[i].begin(),g[i].end(),k)-g[i].begin();
     ll res=sum[i][index]+k*(g[i].size()-index);
     return res;
  };
  auto f=[&](int l,int r,ll k){
    ll res=0;
    if(l/x==r/x || r/x-l/x==1){
       repi(i,l,r+1)res+=min(k,a[i]);
    }
    else {
      int now=l;
      while(now/x==l/x){
         res+=min(k,a[now]);
         now++;
      }
      now=(r/x)*x;
      while(now<=r){
        res+=min(k,a[now]);
        now++;
      }
      now=l/x+1;
      while(now<r/x){
        res+=f2(now,k);
        now++;
      }
    }
    return res;
  };
  rep(qi,q){
    int l,r,k; cin >> l >> r >> k;
    l--;r--;
    ll ans=f(l,r,k);
    anss.push_back(ans);
  }
 
  for(auto u:anss)cout << u << endl;

}
 
 






0