Submission #867328

# Submission time Handle Problem Language Result Execution time Memory
867328 2023-10-28T08:11:45 Z EthanKim8683 Snowball (JOI21_ho_t2) C++17
100 / 100
83 ms 25032 KB
#include<bits/stdc++.h>
using namespace std;
using I=int;
using Lli=long long int;
const I N=200000;
const I Q=200000;
Lli x_arr[N];
Lli w_arr[Q];
vector<tuple<Lli,I,I,Lli>>upds;
vector<tuple<Lli,I,I>>qrys;
Lli ress[N];
I main(){
  cin.tie(0)->sync_with_stdio(0);
  I n,q;cin>>n>>q;
  for(I i=0;i<n;i++)cin>>x_arr[i];
  for(I i=0;i<q;i++)cin>>w_arr[i];
  Lli acc=0,suf=0,pre=0;
  for(I i=0;i<q;i++){
    Lli w=w_arr[i];
    acc+=w;
    if(w>0){
      pre=max(pre,acc);
      upds.push_back({pre+suf,i,1,suf});
    }
    if(w<0){
      suf=max(suf,-acc);
      upds.push_back({pre+suf,i,0,pre});
    }
  }
  for(I i=0;i+1<n;i++)qrys.push_back({x_arr[i+1]-x_arr[i],i,i+1});
  sort(upds.rbegin(),upds.rend());
  sort(qrys.rbegin(),qrys.rend());
  I t1=2;
  Lli len1;
  for(I i=0,j=0;i<qrys.size();i++){
    auto[wid1,l,r]=qrys[i];
    for(;j<upds.size();j++){
      auto[wid2,k,t2,len2]=upds[j];
      if(wid2<wid1)break;
      tie(t1,len1)=tie(t2,len2);
    }
    if(t1==0){
      ress[l]+=len1;
      ress[r]+=max(wid1-len1,0ll);
    }
    if(t1==1){
      ress[l]+=max(wid1-len1,0ll);
      ress[r]+=len1;
    }
    if(t1==2){
      ress[l]+=pre;
      ress[r]+=suf;
    }
  }
  ress[0]+=suf;
  ress[n-1]+=pre;
  for(I i=0;i<n;i++)printf("%lli\n",ress[i]);
}

Compilation message

Main.cpp: In function 'I main()':
Main.cpp:35:18: warning: comparison of integer expressions of different signedness: 'I' {aka 'int'} and 'std::vector<std::tuple<long long int, int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |   for(I i=0,j=0;i<qrys.size();i++){
      |                 ~^~~~~~~~~~~~
Main.cpp:37:11: warning: comparison of integer expressions of different signedness: 'I' {aka 'int'} and 'std::vector<std::tuple<long long int, int, int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     for(;j<upds.size();j++){
      |          ~^~~~~~~~~~~~
Main.cpp:48:14: warning: 'len1' may be used uninitialized in this function [-Wmaybe-uninitialized]
   48 |       ress[r]+=len1;
      |       ~~~~~~~^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4572 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4700 KB Output is correct
9 Correct 1 ms 4700 KB Output is correct
10 Correct 1 ms 4700 KB Output is correct
11 Correct 1 ms 4572 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
16 Correct 1 ms 4700 KB Output is correct
17 Correct 1 ms 4700 KB Output is correct
18 Correct 1 ms 4440 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4572 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4700 KB Output is correct
9 Correct 1 ms 4700 KB Output is correct
10 Correct 1 ms 4700 KB Output is correct
11 Correct 1 ms 4572 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
16 Correct 1 ms 4700 KB Output is correct
17 Correct 1 ms 4700 KB Output is correct
18 Correct 1 ms 4440 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 24 ms 14508 KB Output is correct
21 Correct 24 ms 13260 KB Output is correct
22 Correct 22 ms 14412 KB Output is correct
23 Correct 23 ms 13516 KB Output is correct
24 Correct 26 ms 13616 KB Output is correct
25 Correct 74 ms 23460 KB Output is correct
26 Correct 78 ms 23728 KB Output is correct
27 Correct 71 ms 22704 KB Output is correct
28 Correct 71 ms 22040 KB Output is correct
29 Correct 71 ms 21628 KB Output is correct
30 Correct 69 ms 17940 KB Output is correct
31 Correct 63 ms 17868 KB Output is correct
32 Correct 48 ms 16188 KB Output is correct
33 Correct 8 ms 6608 KB Output is correct
34 Correct 78 ms 22536 KB Output is correct
35 Correct 70 ms 22456 KB Output is correct
36 Correct 69 ms 22180 KB Output is correct
37 Correct 72 ms 23404 KB Output is correct
38 Correct 83 ms 23492 KB Output is correct
39 Correct 72 ms 21852 KB Output is correct
40 Correct 71 ms 24252 KB Output is correct
41 Correct 30 ms 14276 KB Output is correct
42 Correct 55 ms 14284 KB Output is correct
43 Correct 60 ms 25032 KB Output is correct
44 Correct 23 ms 15024 KB Output is correct
45 Correct 69 ms 21940 KB Output is correct
46 Correct 64 ms 23972 KB Output is correct
47 Correct 72 ms 24372 KB Output is correct
48 Correct 66 ms 25008 KB Output is correct