Pagini recente » Cod sursa (job #293335) | Cod sursa (job #252110) | Cod sursa (job #1376924) | Cod sursa (job #1862078) | Cod sursa (job #2893359)
#include <bits/stdc++.h>
#define ull unsigned long long
#define FILES freopen("distincte.in","r",stdin);\
freopen("distincte.out","w",stdout);
#define CMAX 15485863
#define fastio std::ios_base::sync_with_stdio(NULL),cin.tie(NULL),cout.tie(NULL);
#define mp make_pair
#define INF 1e18
#define mod 666013
#define ll long long
#define SMAX 300
#define MAX 100000
#define pb push_back
#define add emplace_back
#define void inline void
using namespace std;
struct solve
{
int first, second, third;
};
int n,k,m,sqr,fr[MAX+5],v[MAX+5],ANS[MAX+5];
ll ans;
solve q[MAX+5];
inline bool cmp(solve a,solve b)
{
if(a.first / sqr != b.first / sqr)
return a.first / sqr < b.first / sqr;
int z = a.first / sqr;
if(z & 1) return a.second < b.second;
else return a.second > b.second;
}
void read(int &a)
{
a = 0;
char c;
while(1)
{
c = getchar();
if(c < '0' || c > '9')
break;
a = a * 10 + c - '0';
}
}
int main()
{
fastio
FILES
read(n),read(k),read(m);
sqr = sqrt(n);
for(int i = 1; i <= n; ++i)
read(v[i]);
for(int i = 0; i < m; ++i)
{
read(q[i].first), read(q[i].second);
q[i].third = i + 1;
}
sort(q,q+m,cmp);
for(int i = q[0].first;i <= q[0].second; ++i)
{
if(!fr[v[i]]) ans += v[i];
fr[v[i]]++;
}
ANS[q[0].third] = ans % mod;
int j = 1, x = q[0].first, y = q[0].second;
while(j < m)
{
while(x > q[j].first)
{
x--;
if(!fr[v[x]]) ans += v[x];
fr[v[x]]++;
}
while(x < q[j].first)
{
fr[v[x]]--;
if(!fr[v[x]]) ans -= v[x];
x++;
}
while(y < q[j].second)
{
y++;
if(!fr[v[y]]) ans += v[y];
fr[v[y]]++;
}
while(y > q[j].second)
{
fr[v[y]]--;
if(!fr[v[y]]) ans -= v[y];
y--;
}
ANS[q[j].third] = ans % mod;
j++;
}
for(int i = 1;i <= m; ++i)
cout << ANS[i] << '\n';
}