Advertisement
a53

pitici

a53
Nov 20th, 2020
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. /* Pitici - O(NlogN)
  2. * Dana Lica
  3. * scor: 100
  4. */
  5. #include <fstream>
  6.  
  7. using namespace std;
  8.  
  9. ifstream f("pitici.in");
  10. ofstream g("pitici.out");
  11.  
  12. using ll = long long;
  13.  
  14. const int NMAX = 2e5 + 1;
  15.  
  16. int N, A[NMAX], Mars[NMAX];
  17.  
  18. ll B, sp[NMAX];
  19.  
  20. static inline void Load ()
  21. {
  22. f.tie(nullptr);
  23.  
  24. f >> N;
  25.  
  26. for(int i = 1; i <= N; ++i)
  27. f >> A[i], sp[i] = sp[i - 1] + 1LL * A[i];
  28.  
  29. return;
  30. }
  31.  
  32. static inline ll Query (int Left, int Right)
  33. {
  34. return sp[Right] - sp[Left - 1];
  35. }
  36.  
  37. static inline int Find (int Index, ll Needed)
  38. {
  39. if(Query(Index, N) < Needed)
  40. return N;
  41.  
  42. if(A[Index] == Needed)
  43. return Index;
  44.  
  45. int Left = Index, Right = N, ans = N;
  46.  
  47. while(Left <= Right)
  48. {
  49. int Mid = ((Left + Right) >> 1);
  50.  
  51. if(Query(Index, Mid) >= Needed)
  52. ans = Mid, Right = Mid - 1;
  53. else
  54. Left = Mid + 1;
  55. }
  56.  
  57. return ans;
  58. }
  59.  
  60. static inline void Update (int Left, int Right, int Val)
  61. {
  62. Mars[Left] += Val;
  63.  
  64. if(Right < N)
  65. Mars[Right + 1] -= Val;
  66.  
  67. return;
  68. }
  69.  
  70. static inline void Solve ()
  71. {
  72. for(int i = 1; i <= N; ++i)
  73. {
  74. f >> B;
  75.  
  76. int poz = Find(i, B);
  77.  
  78. Update(i, poz, +1);
  79. }
  80.  
  81. return;
  82. }
  83.  
  84. static inline void Write ()
  85. {
  86. int ans = -1, cnt = 0;
  87.  
  88. for(int i = 1; i <= N; ++i)
  89. {
  90. Mars[i] += Mars[i - 1];
  91.  
  92. if(Mars[i] > ans)
  93. ans = Mars[i], cnt = 1;
  94. else if(Mars[i] == ans)
  95. ++cnt;
  96. }
  97.  
  98. g << ans << ' ' << cnt << '\n';
  99.  
  100. return;
  101. }
  102.  
  103. int main()
  104. {
  105. Load();
  106.  
  107. Solve();
  108.  
  109. Write();
  110.  
  111. return 0;
  112. }
  113.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement