QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#133152#6630. Triangle CollectionPCTprobability#5 1045ms39984kbC++149.6kb2023-08-01 16:34:332024-07-04 01:06:53

Judging History

你现在查看的是最新测评结果

  • [2024-07-04 01:06:53]
  • 评测
  • 测评结果:5
  • 用时:1045ms
  • 内存:39984kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-01 16:34:33]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define endl "\n"
typedef pair<int, int> Pii;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REP3(i, m, n) for (int i = (m); (i) < int(n); ++ (i))
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(x) begin(x), end(x)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(s) (s).begin(),(s).end()
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define drep(i, n) drep2(i, n, 0)
#define rever(vec) reverse(vec.begin(), vec.end())
#define sor(vec) sort(vec.begin(), vec.end())
#define fi first
#define FOR_(n) for (ll _ = 0; (_) < (ll)(n); ++(_))
#define FOR(i, n) for (ll i = 0; (i) < (ll)(n); ++(i))
#define se second
#define pb push_back
#define P pair<ll,ll>
#define PQminll priority_queue<ll, vector<ll>, greater<ll>>
#define PQmaxll priority_queue<ll,vector<ll>,less<ll>>
#define PQminP priority_queue<P, vector<P>, greater<P>>
#define PQmaxP priority_queue<P,vector<P>,less<P>>
#define NP next_permutation
//const ll mod = 1000000009;
//const ll mod = 998244353;
const ll mod = 1000000007;
const ll inf = 4100000000000000000ll;
const ld eps = ld(0.00000000001);
static const long double pi = 3.141592653589793;
template<class T>void vcin(vector<T> &n){for(int i=0;i<int(n.size());i++) cin>>n[i];}
template<class T,class K>void vcin(vector<T> &n,vector<K> &m){for(int i=0;i<int(n.size());i++) cin>>n[i]>>m[i];}
template<class T>void vcout(vector<T> &n){for(int i=0;i<int(n.size());i++){cout<<n[i]<<" ";}cout<<endl;}
template<class T>void vcin(vector<vector<T>> &n){for(int i=0;i<int(n.size());i++){for(int j=0;j<int(n[i].size());j++){cin>>n[i][j];}}}
template<class T>void vcout(vector<vector<T>> &n){for(int i=0;i<int(n.size());i++){for(int j=0;j<int(n[i].size());j++){cout<<n[i][j]<<" ";}cout<<endl;}cout<<endl;}
void yes(bool a){cout<<(a?"yes":"no")<<endl;}
void YES(bool a){cout<<(a?"YES":"NO")<<endl;}
void Yes(bool a){cout<<(a?"Yes":"No")<<endl;}
void possible(bool a){ cout<<(a?"possible":"impossible")<<endl; }
void Possible(bool a){ cout<<(a?"Possible":"Impossible")<<endl; }
void POSSIBLE(bool a){ cout<<(a?"POSSIBLE":"IMPOSSIBLE")<<endl; }
#define FOR_R(i, n) for (ll i = (ll)(n)-1; (i) >= 0; --(i))
template<class T>auto min(const T& a){ return *min_element(all(a)); }
template<class T>auto max(const T& a){ return *max_element(all(a)); }
template<class T,class F>void print(pair<T,F> a){cout<<a.fi<<" "<<a.se<<endl;}
template<class T>bool chmax(T &a,const T b) { if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a,const T b) { if (b<a) { a=b; return 1; } return 0;}
template<class T> void ifmin(T t,T u){if(t>u){cout<<-1<<endl;}else{cout<<t<<endl;}}
template<class T> void ifmax(T t,T u){if(t>u){cout<<-1<<endl;}else{cout<<t<<endl;}}
ll fastgcd(ll u,ll v){ll shl=0;while(u&&v&&u!=v){bool eu=!(u&1);bool ev=!(v&1);if(eu&&ev){++shl;u>>=1;v>>=1;}else if(eu&&!ev){u>>=1;}else if(!eu&&ev){v>>=1;}else if(u>=v){u=(u-v)>>1;}else{ll tmp=u;u=(v-u)>>1;v=tmp;}}return !u?v<<shl:u<<shl;}
ll modPow(ll a, ll n, ll mod) { if(mod==1) return 0;ll ret = 1; ll p = a % mod; while (n) { if (n & 1) ret = ret * p % mod; p = p * p % mod; n >>= 1; } return ret; }
vector<ll> divisor(ll x){ vector<ll> ans; for(ll i = 1; i * i <= x; i++){ if(x % i == 0) {ans.push_back(i); if(i*i!=x){ ans.push_back(x / ans[i]);}}}sor(ans); return ans; }
ll pop(ll x){return __builtin_popcountll(x);}
ll poplong(ll x){ll y=-1;while(x){x/=2;y++;}return y;}
P hyou(P a){ll x=fastgcd(abs(a.fi),abs(a.se));a.fi/=x;a.se/=x;if(a.se<0){a.fi*=-1;a.se*=-1;}return a;}
P Pplus(P a,P b){ return hyou({a.fi*b.se+b.fi*a.se,a.se*b.se});}
P Ptimes(P a,ll b){ return hyou({a.fi*b,a.se});}
P Ptimes(P a,P b){ return hyou({a.fi*b.fi,a.se*b.se});}
P Pminus(P a,P b){ return hyou({a.fi*b.se-b.fi*a.se,a.se*b.se});}
P Pgyaku(P a){ return hyou({a.se,a.fi});}
template<class T>
struct Sum{
  vector<T> data;
  Sum(const vector<T>& v):data(v.size()+1){
    for(ll i=0;i<v.size();i++) data[i+1]=data[i]+v[i];
  }
  T get(ll l,ll r) const {
    return data[r]-data[l];
  }
};
template<class T>
struct Sum2{
  vector<vector<T>> data;
  Sum2(const vector<vector<T>> &v):data(v.size()+1,vector<T>(v[0].size()+1)){
    for(int i=0;i<v.size();i++) for(int j=0;j<v[i].size();j++) data[i+1][j+1]=data[i][j+1]+v[i][j];
    for(int i=0;i<v.size();i++) for(int j=0;j<v[i].size();j++) data[i+1][j+1]+=data[i+1][j];
  }
  T get(ll x1,ll y1,ll x2,ll y2) const {
    return data[x2][y2]+data[x1][y1]-data[x1][y2]-data[x2][y1];
  }
};
 
void cincout(){
  ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
  cout<< fixed << setprecision(15);
}
struct Segtree{
  vector<ll> node,lazy;
  ll n;
  Segtree(vector<ll> a){
    ll N=a.size();
    n=1;
    while(n<N) n*=2;
    node.resize(2*n);
    lazy.resize(2*n);
    for(int i=0;i<a.size();i++) node[i+n]=a[i];
    for(int i=n-1;i>=1;i--) node[i]=min(node[2*i],node[2*i+1]);
  }
  void eval(ll k){
    if(lazy[k]==0) return;
    if(k<=n-1){
      lazy[2*k]=lazy[2*k]+lazy[k];
      lazy[2*k+1]=lazy[2*k+1]+lazy[k];
    }
    node[k]=node[k]+lazy[k];
    lazy[k]=0;
  }
  void add(int l,int r,int a,int b,int k,int x){
    eval(k);
    if(r<=a||b<=l) return;
    if(l<=a&&b<=r){
      lazy[k]+=x;
      eval(k);
    }
    else{
      add(l,r,a,(a+b)/2,2*k,x);
      add(l,r,(a+b)/2,b,2*k+1,x);
      node[k]=min(node[2*k],node[2*k+1]);
    }
  }
  void add(int l,int r,int x){
    add(l,r,0,n,1,x);
  }
  ll get(int l,int r,int a,int b,int k){
    eval(k);
    if(r<=a||b<=l) return inf;
    if(l<=a&&b<=r){
      return node[k];
    }
    else{
      return min(get(l,r,a,(a+b)/2,2*k),get(l,r,(a+b)/2,b,2*k+1));
    }
  }
  ll get(int l,int r){
    return get(l,r,0,n,1);
  }
};
int main() {
  cincout();
  ll n,q;
  cin>>n>>q;
  vector<ll> a(n+1);
  for(int i=1;i<=n;i++) cin>>a[i];
  vector<ll> b(n+1),c(n+1);
  for(int _=0;_<1;_++){
    ll x,d;
    cin>>x>>d;
    a[x]+=d;
    ll ok=0,ng=0;
    for(int i=1;i<=n;i++) ng+=a[i]/2;
    ng++;
    while(abs(ok-ng)>1){
      ll m=(ok+ng)/2;
      ll k=m;
      for(int i=n;i>=0;i--){
        if(k>=a[i]/2){
          b[i]=a[i]-(a[i]/2)*2;
          c[i]=a[i]/2;
          k-=a[i]/2;
        }
        else{
          b[i]=a[i]-2*k;
          c[i]=k;
          k=0;
        }
      }
      ll p=0;
      ll q=0;
      bool check=true;
      while(q<=n){
        while(c[q]){
          if(p>q*2-1||p>n){
            check=false;
            break;
          }
          ll use=min(c[q],b[p]);
          c[q]-=use;
          b[p]-=use;
          if(b[p]==0) p++;
        }
        if(!check) break;
        q++;
      }
      if(check) ok=m;
      else ng=m;
    }
    cout<<ok<<endl;
    while(true){
      ll m=ok;
      ll k=m;
      for(int i=n;i>=0;i--){
        if(k>=a[i]/2){
          b[i]=a[i]-(a[i]/2)*2;
          c[i]=a[i]/2;
          k-=a[i]/2;
        }
        else{
          b[i]=a[i]-2*k;
          c[i]=k;
          k=0;
        }
      }
      break;
    }
  }
  set<ll> ps,nb;
  for(int i=0;i<=n;i++) if(c[i]) ps.insert(i);
  for(int i=0;i<=n;i++) if(b[i]>=2) nb.insert(i);
  bool ok=true;
  vector<ll> d(2*n+1);
  for(int i=0;i<=n;i++) d[i]+=b[i];
  for(int i=0;i<=n;i++) d[2*i-1]-=c[i];
  for(int i=1;i<=2*n;i++) d[i]+=d[i-1];
  Segtree seg(d);
 /* for(auto e:d) cout<<e<<" ";
  cout<<endl;
  for(int i=0;i<2*n+1;i++) cout<<seg.get(i,i+1)<<" ";
    cout<<endl;*/
  ll sumc=0;
  for(auto e:c) sumc+=e;
  auto badd = [&](int x){
    b[x]++;
    seg.add(x,2*n+1,1);
    if(b[x]>=2) nb.insert(x);
  };
  auto berase = [&](int x){
    if(b[x]){
      b[x]--;
      seg.add(x,2*n+1,-1);
      if(b[x]<=1) nb.erase(x);
    }
    else{
      c[x]--;
      sumc--;
      b[x]++;
      seg.add(x,2*n+1,1);
      seg.add(2*x-1,2*n+1,1);
      if(c[x]==0) ps.erase(x);
      if(b[x]>=2) nb.insert(x);
    }
  };
  auto padd = [&](){
    ok=true;
    if(nb.size()==0){
      ok=false;
      return;
    }
    auto itr=nb.end();
    itr--;
    ll v=(*itr);
   // cout<<"V"<<" "<<v<<endl;
   // for(int i=0;i<2*n+1;i++) cout<<seg.get(i,i+1)<<" ";
   // cout<<endl;
    seg.add(v,2*n+1,-2);
    seg.add(2*v-1,2*n+1,-1);
    if(seg.get(0,2*n+1)<0){
      seg.add(v,2*n+1,2);
      seg.add(2*v-1,2*n+1,1);
      ok=false;
      return;
    }
    if(c[v]==0) ps.insert(v);
    c[v]++;
    sumc++;
    b[v]-=2;
    if(b[v]<2){
      nb.erase(v);
    }
  };
  auto perase = [&](){
    if(ps.size()==0) return;
    auto itr=ps.begin();
    ll v=(*itr);
    b[v]+=2;
    c[v]--;
    sumc--;
    seg.add(v,2*n+1,2);
    seg.add(2*v-1,2*n+1,1);
    if(b[v]>=2) nb.insert(v);
    if(c[v]==0) ps.erase(v);
  };
  for(int _=0;_<q-1;_++){
    ll x,d;
    cin>>x>>d;
    if(d==1){
   /*   for(auto e:b) cout<<e<<" ";
      cout<<endl;
      for(auto e:c) cout<<e<<" ";
      cout<<endl;*/
      badd(x);
    /*  for(auto e:b) cout<<e<<" ";
      cout<<endl;
      for(auto e:c) cout<<e<<" ";
      cout<<endl;  */
      perase();
    /*  for(auto e:b) cout<<e<<" ";
      cout<<endl;
      for(auto e:c) cout<<e<<" ";
      cout<<endl; */
      ok=true;
      while(ok){
     //   cout<<"ADD"<<" "<<nb.size()<<endl;
        padd();
      }
    /*  for(auto e:b) cout<<e<<" ";
      cout<<endl;
      for(auto e:c) cout<<e<<" ";
      cout<<endl; */
    }
    else{
      berase(x);
      perase();
      ok=true;
      while(ok){
        padd();
      }
    }
    cout<<sumc<<endl;
  }
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3828kb

input:

1 23
1485
1 -12
1 -30
1 -20
1 6
1 24
1 5
1 31
1 14
1 -34
1 -22
1 -45
1 37
1 46
1 9
1 22
1 -9
1 9
1 -46
1 -47
1 39
1 36
1 -36
1 50

output:

491
490
490
490
489
489
489
488
488
488
487
487
487
486
486
486
485
485
485
484
484
484
483

result:

wrong answer 2nd numbers differ - expected: '481', found: '490'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Wrong Answer

Test #28:

score: 0
Wrong Answer
time: 4ms
memory: 3844kb

input:

1999 2000
1 1 1 1 0 2 0 2 1 0 2 1 2 2 2 1 2 0 0 1 2 2 0 1 0 1 0 2 0 0 2 1 1 1 1 0 1 2 1 2 1 1 1 1 1 0 2 2 0 2 1 1 2 0 0 2 0 0 2 1 2 0 0 1 1 2 0 2 2 2 1 2 0 2 1 2 0 1 2 2 2 1 1 2 1 1 1 1 0 0 1 1 0 1 2 1 0 0 2 0 2 2 2 0 1 1 2 0 0 1 0 0 2 1 2 1 2 0 1 1 2 2 0 0 1 2 2 1 2 1 2 2 2 0 0 1 1 2 1 1 2 2 2 2 2 ...

output:

660
660
660
661
660
660
660
659
659
659
659
658
659
659
660
659
658
657
658
658
657
656
657
656
655
654
653
653
652
652
651
650
650
649
648
647
646
645
644
645
645
644
645
646
646
646
646
646
646
645
645
645
644
644
644
644
644
645
644
643
642
642
641
640
640
640
641
640
639
640
639
638
637
636
635
...

result:

wrong answer 5th numbers differ - expected: '661', found: '660'

Subtask #4:

score: 5
Accepted

Test #35:

score: 5
Accepted
time: 4ms
memory: 3780kb

input:

2000 1999
0 1 0 3 0 1 0 0 0 0 0 0 0 2 0 0 0 0 3 1 1 0 2 0 0 3 0 0 0 0 0 4 0 0 1 0 1 0 0 0 0 1 2 1 0 0 0 0 7 0 1 3 1 0 1 1 0 3 2 1 0 1 1 3 3 1 0 2 0 0 0 0 0 0 0 0 1 0 0 0 2 0 0 0 0 0 1 2 3 0 1 0 3 3 0 0 0 0 1 0 1 2 0 0 2 2 0 1 2 1 2 0 0 0 1 1 0 1 2 0 0 0 0 2 0 5 0 0 0 0 0 1 0 0 2 0 1 2 0 1 0 0 0 2 0 ...

output:

666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
665
665
665
665
665
665
665
665
665
665
665
665
665
665
665
665
665
666
666
666
666
666
666
666
666
666
666
666
666
666
665
...

result:

ok 1999 numbers

Test #36:

score: 0
Accepted
time: 6ms
memory: 3912kb

input:

1999 2000
938865181 635701131 720186551 12098533 888342577 819466162 677119886 695501777 87063160 544120940 280740814 953384275 462378756 394423771 769842478 563100233 988726627 938258387 941725041 202877851 608668845 507891555 488072389 600920090 738211573 440041095 584208199 334345340 587249363 60...

output:

334310744804
334310744804
334310744805
334310744805
334310744805
334310744805
334310744805
334310744806
334310744805
334310744805
334310744805
334310744805
334310744805
334310744805
334310744805
334310744805
334310744805
334310744805
334310744805
334310744804
334310744805
334310744804
334310744805
3...

result:

ok 2000 numbers

Test #37:

score: 0
Accepted
time: 6ms
memory: 3908kb

input:

1998 2000
953983734 995770518 938631730 961951570 959332856 972648102 943061680 904445058 924304353 960622114 906426330 931936027 957313612 965894280 965137632 988149861 916855162 928712995 923621242 962852409 971372933 948162818 943268160 970351693 997138667 985041992 953192885 954772005 986919660 ...

output:

632914970666
632914970667
632914970666
632914970666
632914970666
632914970665
632914970666
632914970666
632914970666
632914970667
632914970667
632914970667
632914970666
632914970667
632914970666
632914970667
632914970667
632914970667
632914970668
632914970667
632914970668
632914970667
632914970667
6...

result:

ok 2000 numbers

Test #38:

score: 0
Accepted
time: 5ms
memory: 3812kb

input:

2000 1999
0 5 4 1 3 4 1 3 1 0 0 1 4 0 3 5 5 2 3 0 5 3 3 4 5 3 5 5 0 3 4 5 4 0 2 0 0 4 0 5 5 2 2 3 5 5 4 0 3 2 2 2 0 4 5 4 2 2 5 1 5 5 1 4 5 2 0 4 3 1 5 4 5 1 0 3 0 5 2 4 3 0 4 1 2 5 4 1 4 4 1 0 4 1 0 3 5 5 5 3 4 5 5 1 5 5 5 0 0 2 5 0 3 3 2 4 2 1 3 5 3 4 2 5 2 3 2 3 4 5 1 1 2 3 4 3 3 4 2 0 4 0 0 2 1 ...

output:

1655
1655
1656
1656
1656
1655
1655
1655
1656
1656
1656
1655
1656
1656
1656
1657
1657
1657
1657
1657
1658
1657
1658
1657
1657
1657
1657
1657
1657
1657
1656
1657
1656
1656
1656
1655
1656
1656
1656
1656
1656
1657
1657
1657
1657
1657
1658
1657
1657
1657
1657
1657
1657
1657
1657
1657
1657
1657
1657
1657
...

result:

ok 1999 numbers

Test #39:

score: 0
Accepted
time: 943ms
memory: 38336kb

input:

200000 200000
1 4 9 4 6 9 5 8 4 7 8 5 8 4 5 0 10 1 2 5 5 6 2 1 2 5 7 7 5 9 6 6 1 4 6 6 4 2 10 9 6 0 9 10 1 5 7 4 7 5 9 10 0 2 6 10 4 3 7 2 7 7 10 0 5 1 2 2 0 8 10 6 7 4 4 10 0 7 0 8 8 8 6 5 6 5 1 5 10 5 9 3 9 3 6 6 7 7 9 7 5 7 0 7 1 3 7 9 5 0 0 9 10 3 5 3 2 1 8 4 1 0 8 5 7 6 1 1 4 5 1 6 5 3 6 1 5 5 ...

output:

332845
332845
332846
332845
332845
332845
332844
332844
332844
332845
332844
332845
332844
332844
332844
332843
332843
332843
332842
332842
332842
332842
332842
332843
332843
332843
332844
332843
332843
332843
332844
332843
332843
332843
332842
332843
332842
332842
332842
332842
332842
332841
332842...

result:

ok 200000 numbers

Test #40:

score: 0
Accepted
time: 1029ms
memory: 39824kb

input:

200000 200000
85713646 336686856 538585247 278110438 233218655 716436104 837912968 251689084 911446322 701433421 627692917 334396123 413292301 8832435 188412011 689794769 286917079 209754313 519445483 105763643 27705054 168552468 752722351 829700685 747331109 706042730 418755558 614136831 2655911 80...

output:

33341754832470
33341754832470
33341754832471
33341754832470
33341754832471
33341754832470
33341754832470
33341754832470
33341754832470
33341754832470
33341754832470
33341754832470
33341754832471
33341754832470
33341754832471
33341754832470
33341754832471
33341754832471
33341754832471
33341754832472
...

result:

ok 200000 numbers

Test #41:

score: 0
Accepted
time: 962ms
memory: 39856kb

input:

200000 200000
635910513 530707612 43308926 653927427 953772413 886338816 149455282 24772774 715587632 555119024 702589377 349422399 13059257 305480192 768707679 77455076 588537505 275449414 881106189 997605463 699449988 579049544 439144233 339940611 677203754 952180230 954696649 608213997 944927273 ...

output:

33346597165806
33346597165806
33346597165806
33346597165805
33346597165805
33346597165805
33346597165804
33346597165804
33346597165804
33346597165803
33346597165803
33346597165803
33346597165802
33346597165802
33346597165802
33346597165801
33346597165801
33346597165801
33346597165800
33346597165800
...

result:

ok 200000 numbers

Test #42:

score: 0
Accepted
time: 1042ms
memory: 39920kb

input:

200000 200000
323842684 404575711 975846485 26692339 484624497 479820673 79145839 690422479 435950749 721344329 55972947 946532807 537527876 632207792 134109985 92150997 282767325 50309244 942832532 291033288 394196176 355961510 210549616 639079458 254823064 129598231 941770957 38138695 661229827 98...

output:

33357361283426
33357361283426
33357361283427
33357361283427
33357361283427
33357361283428
33357361283428
33357361283428
33357361283429
33357361283429
33357361283429
33357361283430
33357361283430
33357361283430
33357361283431
33357361283431
33357361283431
33357361283432
33357361283432
33357361283432
...

result:

ok 200000 numbers

Test #43:

score: 0
Accepted
time: 1045ms
memory: 39984kb

input:

200000 200000
1000000000 1000000000 1000000000 999999999 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 999999999 1000000000 999999999 1000000000 1000000000 999999999 999999999 1000000000 1000000000 999999999 1000000000 999999999 1000000000 1000000000 1000000000 1000000000 1000000...

output:

66666666633339
66666666633339
66666666633339
66666666633338
66666666633338
66666666633338
66666666633339
66666666633339
66666666633339
66666666633339
66666666633339
66666666633339
66666666633339
66666666633339
66666666633339
66666666633339
66666666633339
66666666633339
66666666633339
66666666633338
...

result:

ok 200000 numbers

Subtask #5:

score: 0
Skipped

Dependency #1:

0%