Language: C++

/**
 *    author:  otera    
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template <class Abel> struct BIT {
private:
	vector<Abel> node; int n;
    Abel UNITY_SUM = 0; //to be set
public:
	BIT(int n_) {
		n = n_; node.resize(n, UNITY_SUM);
	}
	//0-indexed
	void add(int a, Abel w) {
		for (int i = a; i < n; i |= i + 1)node[i] += w;
	}
	//[0,a)
	Abel sum(int a) {
		Abel ret = UNITY_SUM;
		for (int i = a - 1; i >= 0; i = (i&(i + 1)) - 1)ret += node[i];
		return ret;
	}
	//[a,b)
	Abel sum(int a, int b) {
		return sum(b) - sum(a);
	}
	//k-th number (k is 0-indexed)
    int get(int k) {
        ++k;
        int res = 0;
        int n = 1; while(n < (int)node.size()) n *= 2;
        for(int i = n / 2; i > 0; i /= 2) {
            if(res + i < (int)node.size() && node[res + i - 1] < k) {
                k -= node[res + i - 1];
                res += i;
            }
        }
        return res; //0-indexed
    }
    //debug
    void print() {
        for(int i = 0; i < n; ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

template<typename T>
vector<T> compress(vector<T> A){
    sort(A.begin(), A.end());
    A.erase(unique(A.begin(), A.end()), A.end());
    return A;
}

void solve() {
	int k, q; cin >> k >> q;
    vector<int> d(k), ds(k + 1, 0);
    rep(i, k) {
        cin >> d[i];
        ds[i + 1] = ds[i] + d[i];
    }
    rep(i, q) {
        int n, x, m; cin >> n >> x >> m;
        x %= m;
        vector<int> dmod(k);
        rep(j, k) {
            dmod[j] = ds[j] % m;
        }
        int ss = ds[k] % m;
        dco = compress(dmod);
        int sz = (int)dco.size();
        vector<int> cnt(sz, 0);
        rep(j, k) {
            int a = dco.lower_boud(all(dco), dmod[j]) - dco.begin();
            cnt[a] ++;
        }
        BIT<int> bit(cnt);
        int st = m - x;
        int rs = m - ss;
        int cnt = 0;
        int ans = 0;
        while(st + rs <= n) {
            int b = dco.lower_boud(all(dco), st) - dco.begin()
            ans += bit.get(0, b);
            st += rs * cnt;
            st %= m;
        }
        int nokori = n - st;
        for(int j = 0; j < nokori - 1; ++j) {
            if((st + ds[j]) % m < (st + ds[j + 1]) % m) ++ans;
        }
        cout << ans << endl;
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Compiler output:
a.cc: In function 'void solve()':
a.cc:119:9: error: 'dco' was not declared in this scope
  119 |         dco = compress(dmod);
      |         ^~~
a.cc:126:25: error: no matching function for call to 'BIT<long long int>::BIT(std::vector<long long int>&)'
  126 |         BIT<int> bit(cnt);
      |                         ^
a.cc:60:9: note: candidate: 'BIT<Abel>::BIT(long long int) [with Abel = long long int]'
   60 |         BIT(int n_) {
      |         ^~~
a.cc:60:17: note:   no known conversion for argument 1 from 'std::vector<long long int>' to 'long long int'
   60 |         BIT(int n_) {
      |                 ^
a.cc:55:30: note: candidate: 'BIT<long long int>::BIT(const BIT<long long int>&)'
   55 | template <class Abel> struct BIT {
      |                              ^~~
a.cc:55:30: note:   no known conversion for argument 1 from 'std::vector<long long int>' to 'const BIT<long long int>&'
a.cc:55:30: note: candidate: 'BIT<long long int>::BIT(BIT<long long int>&&)'
a.cc:55:30: note:   no known conversion for argument 1 from 'std::vector<long long int>' to 'BIT<long long int>&&'
a.cc:129:13: error: conflicting declaration 'long long int cnt'
  129 |         int cnt = 0;
      |             ^~~
a.cc:121:21: note: previous declaration as 'std::vector<long long int> cnt'
  121 |         vector<int> cnt(sz, 0);
      |                     ^~~
a.cc:134:22: error: no match for 'operator*' (operand types are 'long long int' and 'std::vector<long long int>')
  134 |             st += rs * cnt;
      |                   ~~ ^ ~~~
      |                   |    |
      |                   |    std::vector<long long int>
      |                   long long int
In file included from a.cc:19:
/usr/include/c++/14/complex:400:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator*(const complex<_Tp>&, const complex<_Tp>&)'
  400 |     operator*(const complex<_Tp>& __x, const complex<_Tp>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/complex:400:5: note:   template argument deduction/substitution failed:
a.cc:134:24: note:   mismatched types 'const std::complex<_Tp>' and 'long long int'
  134 |             st += rs * cnt;
      |                        ^~~
/usr/include/c++/14/complex:409:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator*(const complex<_Tp>&, const _Tp&)'
  409 |     operator*(const complex<_Tp>& __x, const _Tp& __y)
      |     ^~~~~~~~
/usr/include/c++/14/complex:409:5: note:   template argument deduction/substitution failed:
a.cc:134:24: note:   mismatched types 'const std::complex<_Tp>' and 'long long int'
  134 |             st += rs * cnt;
      |                        ^~~
/usr/include/c++/14/complex:418:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator*(const _Tp&, const complex<_Tp>&)'
  418 |     operator*(const _Tp& __x, const complex<_Tp>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/complex:418:5: note:   template argument deduction/substitution failed:
a.cc:134:24: note:   'std::vector<long long int>' is not derived from 'const std::complex<_Tp>'
  134 |             st += rs * cnt;
      |                        ^~~