Advertisement
a53

changemin

a53
Apr 24th, 2022
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define MOD 666013
  3. #define NMAX 1000005
  4. using namespace std;
  5. int T,N,V[NMAX],minim,k;
  6. long long cnt,scor,alt;
  7. int st[NMAX];
  8.  
  9. long long mod(long long a,int nr)
  10. {
  11. if(a>nr)
  12. {
  13. a%=nr;
  14. if(a<0)
  15. a+=nr;
  16. }
  17. return a;
  18. }
  19.  
  20. int main()
  21. {
  22. int i;
  23. ifstream fin("changemin.in");
  24. fin>>T>>N;
  25. for(int i=1;i<=N;++i)
  26. fin>>V[i];
  27. st[++k]=INT_MIN;
  28. for(i=N;i>=1;--i)
  29. {
  30. while(V[i]<=st[k]&&k>0)
  31. --k;
  32. cnt+=k;
  33. st[++k]=V[i];
  34. }
  35. ofstream fout("changemin.out");
  36. if(T==1)
  37. {
  38. fout<<cnt;
  39. return 0;
  40. }
  41. k=0;
  42. scor=0;
  43. st[++k]=INT_MIN;
  44. for(i=N;i>=1;--i)
  45. {
  46. while(V[i]<=st[k]&&k>0)
  47. --k;
  48. alt+=k;
  49. st[++k]=V[i];
  50. int j=2;
  51. while(j<=k)
  52. {
  53. scor=mod(1LL*scor+1LL*(cnt)*st[j],MOD);
  54. --cnt;
  55. ++j;
  56. }
  57. }
  58. fout<<scor;
  59. return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement