Advertisement
a53

nr_app

a53
Dec 30th, 2018
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int S[100005],D[100005],v[100005];
  5. int main()
  6. {
  7. ifstream fin("nrapp.in");
  8. ofstream fout("nrapp.out");
  9. int n,vf,stiva[100005];
  10. fin>>n;
  11. for(int i=1;i<=n;++i)
  12. fin>>v[i];
  13. vf=0;
  14. stiva[vf]=n+1;
  15. for(int i=n;i>=1;--i)
  16. {
  17. while(vf>0&&v[i]<=v[stiva[vf]])
  18. --vf;
  19. D[i]=stiva[vf];
  20. stiva[++vf]=i;
  21. }
  22. vf=0;
  23. stiva[vf]=0;
  24. for(int i=1;i<=n;++i)
  25. {
  26. while(vf>0&&v[i]<=v[stiva[vf]])
  27. --vf;
  28. S[i]=stiva[vf];
  29. stiva[++vf]=i;
  30. }
  31. int q,y;
  32. char L;
  33. fin>>q;
  34. while(q--)
  35. {
  36. fin>>L>>y;
  37. if(L=='S')
  38. fout<<S[y]<<'\n';
  39. if(L=='D')
  40. fout<<D[y]<<'\n';
  41. }
  42. return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement