Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- #include <string>
- #include <fstream>
- #include <stdio.h>
- #include <set>
- #include <vector>
- #include <algorithm>
- #include <queue>
- using namespace std;
- #define ll long long
- #define pb push_back
- #define mp make_pair
- //inc f(ll pos, ll x){
- //
- //}
- int main()
- {
- #ifdef _DEBUG
- freopen("in.txt", "r", stdin);
- freopen("out.txt", "w", stdout);
- #endif
- ll n, m;
- scanf("%I64d%I64d", &n, &m);
- vector<ll> a(n);
- for(ll i = 0; i < n; i++){
- scanf("%I64d", &a[i]);
- }
- vector<map<int, int>> f(n);
- for(ll i = 0; i < n; i++){
- for(ll pos = i; pos < n; pos |= pos + 1)
- f[pos][a[i]]++;
- }
- for(ll i = 0; i < m; i++){
- ll pos, l, r, x;
- scanf("%I64d%I64d%I64d", &l, &r, &x);
- l--, r--;
- ll sumy = 0, sumx = 0;
- for(ll pos = r; pos >= 0; pos = (pos & (pos + 1)) - 1){
- auto itt = f[pos].find(x);
- for(auto it = f[pos].begin(); it != itt; it++)
- sumy += it->second;
- }
- for(ll pos = l - 1; pos >= 0; pos = (pos & (pos + 1)) - 1){
- auto itt = f[pos].find(x);
- for(auto it = f[pos].begin(); it != itt; it++)
- sumx += it->second;
- }
- printf("%I64d\n", sumy - sumx);
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment