Advertisement
senb1

krsu 7465 (20 points)

Feb 22nd, 2023
596
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. /*
  2. by: senb1
  3. */
  4.  
  5. #include <bits/stdc++.h>
  6.  
  7. #define ll long long
  8. #define all(x) x.begin(), x.end()
  9. #define fr first
  10. #define sc second
  11. #define mk make_pair
  12.  
  13. using namespace std;
  14.  
  15. const ll mod = 1e3;
  16. const ll maxn = 1e6 + 5;
  17. const ll inf = 1e9 + 6;
  18.  
  19. ll binpow(ll a, ll b, ll mod) {
  20.     ll res = 1;
  21.     while (b > 0) {
  22.         if (b & 1)
  23.             res = res * a % mod;
  24.         a = a * a;
  25.         b >>= 1;
  26.     }
  27.     return res;
  28. }
  29.  
  30. void solve() {
  31.     int n, q;
  32.     cin >> n >> q;
  33.     vector<int> dragon(n);
  34.     for (int i = 0; i < n; i++) {
  35.         cin >> dragon[i];
  36.     }
  37.     while (q--) {
  38.         int pos, s, ans = 0;
  39.         cin >> pos >> s;
  40.         pos--;
  41.         if (s > dragon[pos]) {
  42.             int l = pos - 1, r = pos + 1;
  43.             ans = 1;
  44.             while (s > dragon[l] and l >= 0) {
  45.                 ans++;
  46.                 l--;
  47.             }
  48.             while (s > dragon[r] and r < n) {
  49.                 ans++;
  50.                 r++;
  51.             }
  52.         }
  53.         cout << ans << "\n";
  54.     }
  55. }
  56. /*
  57. 5 3
  58. 4 2 5 3 1
  59. 2 5
  60. 3 4
  61. 5 4
  62. */
  63.  
  64. int main() {
  65.     ios::sync_with_stdio(0);
  66.     cin.tie(0);
  67.  
  68.     int t = 1;
  69.     // cin >> t;
  70.     while (t--)
  71.         solve();
  72. }
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement