Advertisement
Guest User

Untitled

a guest
Jan 29th, 2016
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define INF (int)10e6
  4. #define eps 10e-6
  5. #define mp make_pair
  6. #define pb push_back
  7. #define all(t) t.begin(),t.end()
  8. #define LL long long
  9. #define MOD 1000000
  10.  
  11.  
  12. using namespace std;
  13.  
  14. //ifstream fin ("input.txt");
  15. //ofstream fout ("output.txt");
  16.  
  17. LL ans;
  18. LL n,a,b,c;
  19. stack<LL> S;
  20. stack<LL> minS;
  21. LL x[2000000];
  22.  
  23. int main(){
  24.     std::ios::sync_with_stdio(false);
  25.     //freopen("input.in","r",stdin);
  26.     //freopen("output.out","w",stdout);
  27.  
  28.     cin >> n >> a >> b >> c >> x[0];
  29.     for(int i=1;i<=n;++i){
  30.         x[i]=((a*x[i-1]*x[i-1]+b*x[i-1]+c)/100)%MOD;
  31.         if(x[i]%5<2){
  32.             if(!S.empty()){
  33.                 S.pop();
  34.                 minS.pop();
  35.                 if(!S.empty())
  36.                     ans+=minS.top();
  37.             }
  38.         }
  39.         else{
  40.             S.push(x[i]);
  41.             minS.push(min(minS.top(),x[i]));
  42.             ans+=minS.top();
  43.         }
  44.     }
  45.  
  46.     cout << ans;
  47.  
  48.     return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement