283A - Cows and Sequence - CodeForces Solution


constructive algorithms data structures implementation *1600

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 1e9+7;
const int N = 2e5+8;
int n, t, a, x, k, pos, tot, arr[N], y[N];
void solve(){
  cin>>n;
  pos = 0, tot = 0LL;
  arr[0] = 0; ++pos;
  for(int i = 0; i < n; i++){
    cin>>t;
    if(t == 1){
      cin>>x>>a;
      tot += (a*x);
      arr[x-1] += a;
    } else if(t == 2){
      cin>>k;
      y[pos++] = k;
      tot += k;
    } else if(t == 3){
      --pos;
      tot -= arr[pos];
      tot -= (y[pos] + 0);
      if(pos > 0){
        arr[pos-1] += arr[pos];
      }
      arr[pos] = 0;
    }
    cout<<fixed<<setprecision(8)<<(long double)tot/(long double)pos<<'\n';
  }
}
int32_t main()
{
  cin.tie(0)->sync_with_stdio(false);
  int test_cases = 1;
  // cin>>test_cases;
  while(test_cases--){
    solve();
  }
}


Comments

Submit
0 Comments
More Questions

361A - Levko and Table
5E - Bindian Signalizing
687A - NP-Hard Problem
1542C - Strange Function
961E - Tufurama
129D - String
888A - Local Extrema
722B - Verse Pattern
278A - Circle Line
940A - Points on the line
1742C - Stripes
1742F - Smaller
1742B - Increasing
1742A - Sum
1742D - Coprime
390A - Inna and Alarm Clock
1398B - Substring Removal Game
1742G - Orray
416B - Art Union
962A - Equator
803B - Distances to Zero
291A - Spyke Talks
1742E - Scuza
1506D - Epic Transformation
1354G - Find a Gift
1426F - Number of Subsequences
1146B - Hate "A"
1718C - Tonya and Burenka-179
834A - The Useless Toy
1407D - Discrete Centrifugal Jumps