Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int N = 1100000;
- int ans[N + 1];
- const int dim = 1 << 12;
- int bp = dim;
- char buff[dim];
- char next_ch()
- {
- if(bp == dim)
- {
- fread(buff, 1, dim, stdin);
- bp = 0;
- }
- return (char)buff[bp++];
- }
- void get(int &a)
- {
- a = 0;
- char c;
- do{
- c = next_ch();
- }while(c < '0' || '9' < c);
- do{
- a = a * 10 + c - '0';
- c = next_ch();
- }while('0' <= c && c <= '9');
- }
- int main()
- {
- freopen("vsecvente.in", "r", stdin);
- freopen("vsecvente.out", "w", stdout);
- int n, a, b, c;
- get(n);
- if(n == 1)
- {
- get(a);
- ans[a]++;
- }
- else
- {
- get(a);
- get(b);
- if(a <= b)
- ans[a]++;
- if(n >= 3)
- {
- for(int i = 3; i <= n; i++)
- {
- get(c);
- if(a > b && b <= c)///echivalent cu ambele inactive
- ans[b]++;
- if(a <= b && b > c)///echivalent cu ambele active
- ans[b]--;
- a = b;
- b = c;
- }
- }
- if(a > b)
- ans[b]++;
- }
- for(int i = 1; i <= N; i++)
- ans[i] += ans[i - 1];
- int q, x;
- get(q);
- for(int i = 1; i<= q; i++)
- {
- get(x);
- cout << ans[x] << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement