Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define INF (int)10e6
- #define eps 10e-6
- #define mp make_pair
- #define pb push_back
- #define all(t) t.begin(),t.end()
- #define LL long long
- #define MOD 1000000
- using namespace std;
- //ifstream fin ("input.txt");
- //ofstream fout ("output.txt");
- LL ans;
- LL n,a,b,c;
- stack<LL> S;
- stack<LL> minS;
- LL x[2000000];
- int main(){
- std::ios::sync_with_stdio(false);
- //freopen("input.in","r",stdin);
- //freopen("output.out","w",stdout);
- cin >> n >> a >> b >> c >> x[0];
- for(int i=1;i<=n;++i){
- x[i]=((a*x[i-1]*x[i-1]+b*x[i-1]+c)/100)%MOD;
- if(x[i]%5<2){
- if(!minS.empty()){
- minS.pop();
- if(!minS.empty())
- ans+=minS.top();
- }
- else
- continue;
- }
- else{
- minS.push(min(minS.top(),x[i]));
- ans+=minS.top();
- }
- }
- cout << ans;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement