Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define MOD 666013
- #define NMAX 1000005
- using namespace std;
- int T,N,V[NMAX],minim,k;
- long long cnt,scor,alt;
- int st[NMAX];
- long long mod(long long a,int nr)
- {
- if(a>nr)
- {
- a%=nr;
- if(a<0)
- a+=nr;
- }
- return a;
- }
- int main()
- {
- int i;
- ifstream fin("changemin.in");
- fin>>T>>N;
- for(int i=1;i<=N;++i)
- fin>>V[i];
- st[++k]=INT_MIN;
- for(i=N;i>=1;--i)
- {
- while(V[i]<=st[k]&&k>0)
- --k;
- cnt+=k;
- st[++k]=V[i];
- }
- ofstream fout("changemin.out");
- if(T==1)
- {
- fout<<cnt;
- return 0;
- }
- k=0;
- scor=0;
- st[++k]=INT_MIN;
- for(i=N;i>=1;--i)
- {
- while(V[i]<=st[k]&&k>0)
- --k;
- alt+=k;
- st[++k]=V[i];
- int j=2;
- while(j<=k)
- {
- scor=mod(1LL*scor+1LL*(cnt)*st[j],MOD);
- --cnt;
- ++j;
- }
- }
- fout<<scor;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement