Pagini recente » Borderou de evaluare (job #3123485) | Borderou de evaluare (job #842085) | Cod sursa (job #1965103) | Borderou de evaluare (job #696585) | Cod sursa (job #2572403)
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define fi first
#define se second
#define inf (INT_MAX/2-1)
#define infl (1LL<<60)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define sz(a) (int)(a).size()
#define all(a) begin(a),end(a)
#define y0 y5656
#define y1 y7878
#define aaa system("pause");
#define dbg(x) cerr<<(#x)<<": "<<(x)<<'\n',aaa
#define dbga(x,n) cerr<<(#x)<<"[]: ";for(int _=0;_<n;_++)cerr<<x[_]<<' ';cerr<<'\n',aaa
#define dbgs(x) cerr<<(#x)<<"[stl]: ";for(int _:x)cerr<<_<<' ';cerr<<'\n',aaa
#define dbgp(x) cerr<<(#x)<<": "<<x.fi<<' '<<x.se<<'\n',aaa
#define maxn 100000
using namespace std;
ifstream fin ("distincte.in");
ofstream fout ("distincte.out");
struct yes {
int fi, se, ans, ind;
};
int v[maxn+5], fv[maxn+5];
const int mod = 666013;
vector<yes> qry;
void mad (int &a, int b) {
a += b;
while (a >= mod) a -= mod;
}
void msb (int &a, int b) {
a -= b;
while (a < 0) a += mod;
}
void aduce (int &sum, int &ceam, int unde) {
int j;
if (ceam < unde) {
for (j = ceam+1; j <= unde; j++) {
fv[v[j]]++;
if (fv[v[j]] == 1) mad(sum, v[j]);
}
} else if (ceam > unde) {
for (j = ceam; j > unde; j--) {
fv[v[j]]--;
if (fv[v[j]] == 0) msb(sum, v[j]);
}
}
ceam = unde;
}
int main () {
int n, k, m; fin >> n >> k >> m;
int i;
for (i = 1; i <= n; i++) fin >> v[i];
qry.resize(m);
for (i = 0; i < m; i++) {
fin >> qry[i].fi >> qry[i].se;
qry[i].ind = i;
}
int szb = sqrt(n); szb += (szb*szb < n);
sort(all(qry), [&szb](yes a, yes b) {
if (a.fi/szb != b.fi/szb) return a.fi/szb < b.fi/szb;
return a.se < b.se;});
pii ceam = make_pair(0, 0);
int sum = 0;
for (i = 0; i < m; i++) {
aduce(sum, ceam.se, qry[i].se);
aduce(sum, ceam.fi, qry[i].fi);
qry[i].ans = sum;
}
sort(all(qry), [](yes a, yes b){return a.ind < b.ind;});
for (i = 0; i < m; i++) fout << qry[i].ans << '\n';
fin.close(); fout.close();
return 0;
}