Advertisement
Anon2005

vsecvente

Mar 22nd, 2023
806
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.41 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int N = 1100000;
  5.  
  6. int ans[N + 1];
  7.  
  8. const int dim = 1 << 12;
  9.  
  10. int bp = dim;
  11. char buff[dim];
  12.  
  13. char next_ch()
  14. {
  15.     if(bp == dim)
  16.     {
  17.         fread(buff, 1, dim, stdin);
  18.         bp = 0;
  19.     }
  20.     return (char)buff[bp++];
  21. }
  22.  
  23. void get(int &a)
  24. {
  25.     a = 0;
  26.     char c;
  27.     do{
  28.         c = next_ch();
  29.     }while(c < '0' || '9' < c);
  30.     do{
  31.         a = a * 10 + c - '0';
  32.         c = next_ch();
  33.     }while('0' <= c && c <= '9');
  34. }
  35.  
  36. int main()
  37. {
  38.     freopen("vsecvente.in", "r", stdin);
  39.     freopen("vsecvente.out", "w", stdout);
  40.     int n, a, b, c;
  41.     get(n);
  42.     if(n == 1)
  43.     {
  44.         get(a);
  45.         ans[a]++;
  46.     }
  47.     else
  48.     {
  49.         get(a);
  50.         get(b);
  51.         if(a <= b)
  52.             ans[a]++;
  53.         if(n >= 3)
  54.         {
  55.             for(int i = 3; i <= n; i++)
  56.             {
  57.                 get(c);
  58.                 if(a > b && b <= c)///echivalent cu ambele inactive
  59.                     ans[b]++;
  60.                 if(a <= b && b > c)///echivalent cu ambele active
  61.                     ans[b]--;
  62.                 a = b;
  63.                 b = c;
  64.             }
  65.         }
  66.         if(a > b)
  67.             ans[b]++;
  68.     }
  69.     for(int i = 1; i <= N; i++)
  70.         ans[i] += ans[i - 1];
  71.     int q, x;
  72.     get(q);
  73.     for(int i = 1; i<= q; i++)
  74.     {
  75.         get(x);
  76.         cout << ans[x] << '\n';
  77.     }
  78.     return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement