【CodeChef】LCH15JGH Many bananas
暴力可以水过。
#include<bits/stdc++.h>
using namespace std;
char inc;
inline void get(int& x)
{
x = 0;inc = getchar();
while(!isdigit(inc))inc=getchar();
while(isdigit(inc))
{
x=x*10+inc-'0';
inc=getchar();
}
}
#define maxn 100010
int n,m,a[maxn],vmax;
char op[2];
int main()
{
get(n);
int x,y;
for(int i=1;i<=n;i++)
{
get(x);get(y);
a[x] = y;
vmax = max(vmax,x);
}
get(m);
for(int i=1;i<=m;i++)
{
scanf("%s",op);get(x);
if(*op=='?')
{
long long tot = 0;
for(int j=2;j<=vmax;j++)
{
tot+=(x%j)*(long long)a[j];
}
printf("%lld\n",tot);
}
else if(*op=='+')
{
a[x]++;vmax=max(vmax,x);
}
else
{
a[x]--;
for(int j=vmax;j>=1;j--)
if(a[j])
{
vmax = j;
break;
}
}
}
return