Problem:
Problem G: Painting
Problem
長さ$N$の数列$X$が与えられる。初期状態では$X$の要素は全て$0$である。加えて、$M$個の整数のペア$(A_i, B_i)$が与えられる。各ペアに対し以下の操作を行い、最終的な数列$X$を出力せよ。
整数$j$ $(1 \le j \le N)$に対し、$(A_i+j)$を$B_i$で割った余りを$X_j$に加える。
Input
入力は以下の形式で与えられる。
$N$ $M$
$A_1$ $B_1$
$A_2$ $B_2$
:
$A_M$ $B_M$
$1$行目に、与えられる数列の要素数$N$、ペアの数$M$が空白区切りで与えられる。
続く$M$行に、$i$番目のペア$(A_i, B_i)$が空白区切りで与えられる。
Constraints
入力は以下の条件を満たす。
$1 \le N, M \le 10^5$
$0 \le A_i < B_i \le 10^9 (1 \le i \le M)$
与えられる入力は全て整数である
Output
操作後の数列を$N$行で出力せよ。$j$行目に$X_j$を出力せよ。
Sample Input 1
5 3
1 4
3 7
0 1000
Sample Output 1
7
10
9
5
8
Sample Input 2
14 12
1 4
2 3
0 5
1 4
1 2
0 8
0 2
0 10
0 1
0 8
3 10
1 10
Sample Output 2
15
24
25
31
35
44
32
25
24
15
16
25
31
40

Submitted solutions:

code_snippet: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <cstdlib>
#include <sstream>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
typedef unsigned int ull;
typedef pair<ll,ll> pil;
const ll ll_INF = 0x3f3f3f3f3f3f3f3f;
const int int_INF = 0x3f3f3f3f;
const double EPS = 1e-7;
#define R register
#define _max(a,b)  ((a)>(b)?(a):(b))
#define _min(a,b)  ((a)<(b)?(a):(b))
#define _abs(a)    ((a)> 0 ?(a):-(a))
#define _swap(a,b) ((a)^=(b)^=(a)^=(b))
#define _eql(x,y)  (_abs((x) - (y))<EPS)

const int MX = 1000010;
int _r() {
    int x = 0, f = 1;
    char c = getchar();
    while (c > '9' || c < '0') { if (c == '-')f = -1; c = getchar(); }
    while (c >= '0' && c <= '9')x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
    return f==-1?-x:x;
}
 
map<pil,ll> cnt;
int n,m;
ll sum;
void Init() {
    cnt.clear();
    n=_r();
    m=_r();
    pil now;
    for(int i=0;i<m;i++){
        now.first=_r(),now.second=_r();
        sum+=now.first;
        cnt[now]++;
    }
}
ll ans[MX]={0};
void solve() {
    for(auto it : cnt){
        pil now=it.first;
        for(int i=now.second-now.first;i<=n;i+=now.second){
            ans[i]-=now.second*cnt[now];
        }
    }
    for(int i=1;i<=n;i++){
        sum+=ans[i]+m;
        printf("%lld\n",sum);
    }
}
int main() {
    //freopen("data.in", "r", stdin);
    //freopen("data.out", "w", stdout);
    int t = 1;
    while (t--) {
        Init();
        solve();
    }
    return 0;
}
accuracy: 1
time_ms: 130
memory_kb: 10152
final_rank: 10

code_snippet: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <cstdlib>
#include <sstream>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
typedef unsigned int ull;
typedef pair<ll,ll> pil;
const ll ll_INF = 0x3f3f3f3f3f3f3f3f;
const int int_INF = 0x3f3f3f3f;
const double EPS = 1e-7;
#define R register
#define _max(a,b)  ((a)>(b)?(a):(b))
#define _min(a,b)  ((a)<(b)?(a):(b))
#define _abs(a)    ((a)> 0 ?(a):-(a))
#define _swap(a,b) ((a)^=(b)^=(a)^=(b))
#define _eql(x,y)  (_abs((x) - (y))<EPS)

const int MX = 1000010;
int _r() {
    int x = 0, f = 1;
    char c = getchar();
    while (c > '9' || c < '0') { if (c == '-')f = -1; c = getchar(); }
    while (c >= '0' && c <= '9')x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
    return f==-1?-x:x;
}
 
map<pil,ll> cnt;
int n,m;
int sum;
void Init() {
    cnt.clear();
    n=_r();
    m=_r();
    pil now;
    for(int i=0;i<m;i++){
        now.first=_r(),now.second=_r();
        sum+=now.first;
        cnt[now]++;
    }
}
ll ans[MX]={0};
void solve() {
    for(auto it : cnt){
        pil now=it.first;
        for(int i=now.second-now.first;i<=n;i+=now.second){
            ans[i]-=now.second*cnt[now];
        }
    }
    for(int i=1;i<=n;i++){
        sum+=ans[i]+m;
        printf("%lld\n",sum);
    }
}
int main() {
    //freopen("data.in", "r", stdin);
    //freopen("data.out", "w", stdout);
    int t = 1;
    while (t--) {
        Init();
        solve();
    }
    return 0;
}
accuracy: 0.3384615384615385
time_ms: 20
memory_kb: 10148
final_rank: 20

code_snippet: #include <algorithm>
#include <iostream>
#include <vector>
#include <map>
using namespace std;

int main() {
    int n, m; cin >> n >> m;
    map<pair<int, int>, int> mp;
    for (int i = 0; i < m; i++) {
        int a, b; cin >> a >> b;
        mp[{a, b}]++;
    }
    vector<long long> imos(n, m);
    for (auto &p: mp) {
        long long a = p.first.first, b = p.first.second, c = p.second;
        imos[0] += a * c;
        for (int i = b - a - 1; i < n; i += b) imos[i] -= b * c;
    }
    for (int i = 0; i + 1 < n; i++) imos[i + 1] += imos[i];
    for (auto x: imos) cout << x << endl;
    return 0;
}
accuracy: 1
time_ms: 150
memory_kb: 9668
final_rank: 9

code_snippet: #include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <climits>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <map>
#include <tuple>
#include <iostream>
#include <deque>
#include <array>
#include <set>
#include <functional>
#include <memory>
#include <stack>
#include <numeric>
#include <climits>
#include <cfloat>
#include <bitset>

int main() {
	int n, m; std::cin >> n >> m;
	std::vector<std::vector<long long int>> lower(static_cast<int>(std::sqrt(n)) + 1);
	for (auto i = 0; i < lower.size(); ++i) lower[i] = std::vector<long long int>(i + 1, 0);
	std::vector<long long int> all(n, 0);
	for (auto _i = 0; _i < m; ++_i) {
		int a, b; std::cin >> a >> b;
		if (b <= lower.size()) {
			for (auto j = 0; j < b; ++j) {
				lower[b - 1][j] += (a + j + 1) % b;
			}
		}
		else {
			all[0] += a + 1;
			all[1] -= a;
			for (auto j = b - a - 1; j < n; j += b) {
				all[j] -= b;
				if (j + 1 < n) all[j + 1] += b;
			}
		}
	}
	for (auto i = 1; i < n; ++i) all[i] += all[i - 1];
	for (auto i = 1; i < n; ++i) all[i] += all[i - 1];
	for (auto i = 0; i < n; ++i) {
		long long int sum = 0LL;
		for (const auto& l : lower) sum += l[i % l.size()];
		std::cout << all[i] + sum << '\n';
	}
}
accuracy: 1
time_ms: 280
memory_kb: 3888
final_rank: 2

code_snippet: #include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define REP(i,n) for(ll i =0;i<n;++i)

int main(){
  int n,m;
  cin>>n>>m;
  vector<int> a(m),b(m);
  REP(i,m)cin>>a[i]>>b[i];
  int k=200;
  vector<vector<ll>> cnt(k);
  REP(i,k)cnt[i].resize(i);
  vector<ll> sum(n);
  REP(i,m){
      if(b[i]>=k){
          int pos=b[i]-a[i]-1;
          while(pos<n){
              sum[pos]+=b[i];
              pos+=b[i];
          }
      }else{
          cnt[b[i]][(b[i]-a[i]%b[i])%b[i]]+=b[i];
      }
  }
  ll ans=0;
  REP(i,m)ans+=(a[i]+1)%b[i];
  cout<<ans<<endl;
  for(int j=1;j<n;++j){
      ans+=m;
      for(int i=1;i<k;++i){
          ans-=cnt[i][(j+1)%i];
      }
      ans-=sum[j];
      cout<<ans<<endl;
  }
}
accuracy: 1
time_ms: 180
memory_kb: 4432
final_rank: 1

code_snippet: #include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define REP(i,n) for(ll i =0;i<n;++i)

int main(){
  int n,m;
  cin>>n>>m;
  vector<int> a(m),b(m);
  REP(i,m)cin>>a[i]>>b[i];
  int k=200;
  vector<vector<ll>> cnt(k);
  REP(i,k)cnt[i].resize(i);
  vector<ll> sum(n);
  REP(i,m){
      if(b[i]>=k){
          int pos=b[i]-a[i];
          while(pos<n){
              sum[pos]+=b[i];
              pos+=b[i];
          }
      }else{
          cnt[b[i]][(b[i]-a[i]%b[i])%b[i]]+=b[i];
      }
  }
  ll ans=0;
  REP(i,m)ans+=(a[i]+1)%b[i];
  cout<<ans<<endl;
  for(int j=1;j<n;++j){
      ans+=m;
      for(int i=1;i<k;++i){
          ans-=cnt[i][(j+1)%i];
      }
      ans-=sum[j];
      cout<<ans<<endl;
  }
}
accuracy: 0.3384615384615385
time_ms: 150
memory_kb: 4248
final_rank: 16

code_snippet: #include <bits/stdc++.h>

using namespace std;

struct Item {
    int A;
    int B;
    int count;
    int time;

    int diff() const {
        return B - A;
    }

    bool operator<(const Item &rhs) const {
        return time > rhs.time;
    }
};

priority_queue<Item> Q;

int geta = 0;

void add(int A, int B, int count, int time) {
    Q.push({A, B, count, time});
}


long long update(int time) {
    long long dec_sum = 0;
    while (Q.size()) {
        auto q = Q.top();
        if (q.time > time) {
            break;
        }
        Q.pop();
        add(q.A, q.B, q.count, time + q.B);
        dec_sum += 1ll * q.B * q.count;
    }

    return dec_sum;
}

int main() {
    int N, M;
    cin >> N >> M;

    map<pair<int, int>, int> counter;
    long long sum = 0;
    int cnt = 0;
    for (int i = 0; i < M; i++) {
        int A, B;
        cin >> A >> B;
        if (B > 1) {
            counter[{A, B}]++;
            sum += A % B;
            cnt++;
        }
    }
    for (auto i : counter) {
        add(i.first.first, i.first.second, i.second, i.first.second - i.first.first - 1);
    }

    for (int i = 0; i < N; i++) {
        sum += cnt;
        sum -= update(i);
        cout << sum << endl;
    }


}
accuracy: 1
time_ms: 800
memory_kb: 11164
final_rank: 14

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 100005

ll N,M;
ll diff[NUM];

int main(){

	scanf("%lld %lld",&N,&M);

	for(int i = 0; i < N; i++){
		diff[i] = 0;
	}

	int loc;
	ll A,B;
	ll sum_ADD = M;

	for(int loop = 0; loop < M; loop++){

		scanf("%lld %lld",&A,&B);
		sum_ADD += A;

		loc = B-A-1;

		while(loc < N){

			diff[loc] -= B;
			loc += B;
		}
	}

	for(int i = 0; i < N; i++){

		diff[i] += diff[i-1];
	}

	for(ll i = 0; i < N; i++){

		printf("%lld\n",sum_ADD+diff[i]+i*M);
	}

	return 0;
}
accuracy: 1
time_ms: 1300
memory_kb: 3960
final_rank: 11

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 100005

int N,M;
ll diff[NUM];

int main(){

	scanf("%d %d",&N,&M);

	for(int i = 0; i < N; i++){
		diff[i] = 0;
	}

	int loc;
	ll A,B;
	ll sum_ADD = M;

	for(int loop = 0; loop < M; loop++){

		scanf("%lld %lld",&A,&B);
		sum_ADD += A;

		loc = B-A-1;

		while(loc < N){

			diff[loc] -= B;
			loc += B;
		}
	}

	for(int i = 0; i < N; i++){

		diff[i] += diff[i-1];
	}

	for(int i = 0; i < N; i++){

		printf("%lld\n",sum_ADD+diff[i]+i*M);
	}

	return 0;
}
accuracy: 0.3384615384615385
time_ms: 10
memory_kb: 3760
final_rank: 15

code_snippet: #include "bits/stdc++.h"

#pragma warning(disable:4996)
using namespace std;
using ld = long double;

typedef vector<pair<long long int,long long int>> DP;

DP connect(const DP&l, const DP&r) {
	DP k(l.size()+r.size()-1,make_pair(1e18,1e18));
	for (int i = 0; i < l.size(); ++i) {
		for (int j = 0; j < r.size(); ++j) {
			auto x = make_pair(l[i].first + r[j].first, l[i].second + r[j].second);

			k[i + j] = min(k[i + j], x);

		}
	}
	return k;
}
DP dfs(const int now, const int from,
	const vector<vector<int>>&edges,vector<int>&overs) {

	long long int over_num=overs[now];
	DP v(2);
	v[0]=make_pair(over_num,0);
	v[1]=make_pair(over_num-1,0);

	vector<vector<pair<long long int,long long int>>>ps;
	for (auto e : edges[now]) {
		if(e==from)continue;
		ps.push_back(dfs(e,now,edges,overs));
	}
	sort(ps.begin(), ps.end(), [](const vector < pair<long long int, long long int>>&l, const vector<pair<long long int, long long int>>&r) {
		return l.size()<r.size();
	});
	for (auto p : ps) {
		v=connect(v,p);
	}
	for (auto &k : v) {
		k.second+=abs(k.first);
	}
	return v;
}
int main() {
	int N,M;cin>>N>>M;

	int K=sqrt(N);
	long long int sum=0;
	long long int zero_ans=0;
	vector<long long int>sas(N);

	vector<vector<long long int>>nums;
	for (int i = 0; i < K; ++i) {
		nums.push_back(vector<long long int>(i,0));
	}
	for (int i = 0; i < M; ++i) {
		int a,b;cin>>a>>b;
		a=(a+1)%b;
		if (K > b) {
			nums[b][a]++;
		}
		else {
			sum++;
			zero_ans+=a;
			for (int j = b - a; j < N; j += b) {
				sas[j]-=b;
			}
		}
	}

	vector<long long int>anss(N);

	long long int pre=zero_ans;
	long long int small_sum = 0;
	long long int small_cnt = 0;
	for (int j = 1; j < K; ++j) {
		for (int k = 0; k < j; ++k) {
			small_sum += nums[j][k] * k;
			small_cnt += nums[j][k];
		}
	}
	{
		anss[0]+=zero_ans;
		anss[0]+=small_sum;
	}
	long long int small_pre=small_sum;

	for (int i = 1; i < N; ++i) {
		pre+=sum;
		pre+=sas[i];
		anss[i]=pre;

		small_sum+=small_cnt;
		for (long long int j = 1; j < K; ++j) {
			small_sum-=j*nums[j][(1000000*j-i)%j];
		}
		anss[i]+=small_sum;
	}
	for(auto ans:anss)cout<<ans<<endl;
	return 0;
}
accuracy: 1
time_ms: 360
memory_kb: 4676
final_rank: 4

code_snippet: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(ll i=(ll)m ; i < (ll) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

ll a[101010],cnt[500][500];
int main(){
    ll n,m;
    cin>>n>>m;
    rep(i,m){
        ll x,y;
        cin>>x>>y;
        if(y<400)cnt[y][x]++;
        else {
            a[0]+=x+1;
            a[1]-=x;
            ll z=y-x-1;
            while(z<=n){
                a[z]-=y;
                a[z+1]+=y;
                z+=y;
            }
        }
    }
    rep(i,n)a[i+1]+=a[i];    
    rep(i,n)a[i+1]+=a[i];
    rep(i,400){
        if(i==0)continue;
        ll sum=0,num=0;
        rep(j,400)sum+=cnt[i][j]*j,num+=cnt[i][j];
        rep(j,n){
            sum+=num;
            sum-=cnt[i][(n*i-j-1)%i]*i;
            a[j]+=sum;
        }
    }
    rep(i,n)cout<<a[i]<<endl;    
    return 0;
}
accuracy: 1
time_ms: 410
memory_kb: 4228
final_rank: 3

code_snippet: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(ll i=(ll)m ; i < (ll) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

ll a[101010],cnt[500][500];
int main(){
    ll n,m;
    cin>>n>>m;
    rep(i,m){
        ll x,y;
        cin>>x>>y;
        if(y<400)cnt[y][x]++;
        else {
            a[0]+=(x+1)%y;
            a[1]-=a[0]-1;
            ll z=y-x;
            while(z<=n){
                a[z]-=y;
                a[z+1]+=y;
                z+=y;
            }
        }
    }
    rep(i,n)a[i+1]+=a[i];    
    rep(i,n)a[i+1]+=a[i];
    rep(i,400){
        if(i==0)continue;
        ll sum=0,num=0;
        rep(j,400)sum+=cnt[i][j]*j,num+=cnt[i][j];
        rep(j,n){
            sum+=num;
            sum-=cnt[i][(n*i-j-1)%i]*i;
            a[j]+=sum;
        }
    }
    rep(i,n)cout<<a[i]<<endl;    
    return 0;
}
accuracy: 0.3384615384615385
time_ms: 350
memory_kb: 3596
final_rank: 18

code_snippet: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(ll i=(ll)m ; i < (ll) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

ll a[101010],cnt[500][500];
int main(){
    ll n,m;
    cin>>n>>m;
    rep(i,m){
        ll x,y;
        cin>>x>>y;
        if(y<400)cnt[y][x]++;
        else {
            a[0]+=x+1;
            a[1]-=x;
            ll z=y-x;
            while(z<=n){
                a[z]-=y;
                a[z+1]+=y;
                z+=y;
            }
        }
    }
    rep(i,n)a[i+1]+=a[i];    
    rep(i,n)a[i+1]+=a[i];
    rep(i,400){
        if(i==0)continue;
        ll sum=0,num=0;
        rep(j,400)sum+=cnt[i][j]*j,num+=cnt[i][j];
        rep(j,n){
            sum+=num;
            sum-=cnt[i][(n*i-j-1)%i]*i;
            a[j]+=sum;
        }
    }
    rep(i,n)cout<<a[i]<<endl;    
    return 0;
}
accuracy: 0.3384615384615385
time_ms: 340
memory_kb: 3628
final_rank: 17

code_snippet: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

ll a[101010],cnt[500][500];
int main(){
    ll n,m;
    cin>>n>>m;
    rep(i,m){
        ll x,y;
        cin>>x>>y;
        if(y<400)cnt[y][x]++;
        else {
            a[0]+=x+1;
            a[1]-=x;
            int z=y-x;
            while(z<=n){
                a[z]-=y;
                a[z+1]+=y;
                z+=y;
            }
        }
    }
    rep(i,n)a[i+1]+=a[i];    
    rep(i,n)a[i+1]+=a[i];
    rep(i,400){
        if(i==0)continue;
        ll sum=0,num=0;
        rep(j,400)sum+=cnt[i][j]*j,num+=cnt[i][j];
        rep(j,n){
            sum+=num;
            sum-=cnt[i][(n*i-j-1)%i]*i;
            a[j]+=sum;
        }
    }
    rep(i,n)cout<<a[i]<<endl;    
    return 0;
}
accuracy: 0.3384615384615385
time_ms: 340
memory_kb: 3700
final_rank: 19

code_snippet: #include <iostream>
#include <vector>
using namespace std;

const int DIV = 350;

int N, M;
vector<long long> A, B;

int main() {
    cin >> N >> M;
    A.resize(M); B.resize(M);
    for (int i = 0; i < M; ++i) scanf("%lld %lld", &A[i], &B[i]);

    vector<vector<long long> > sb(DIV, vector<long long>(DIV, 0));
    vector<long long> imos(N+1, 0);
    long long geta = 0;
    for (int i = 0; i < M; ++i) {
        if (B[i] < DIV) {
            for (int j = 0; j < B[i]; ++j) {
                long long q = (A[i] + j + 1) % B[i];
                sb[B[i]][j] += q;
            }
        }
        else {
            ++geta;
            imos[0] += A[i];
            imos[N] += -1 - (A[i]+N)%B[i];
            for (int q = B[i]-A[i]-1; q < N; q += B[i]) {
                imos[q] -= B[i];
            }
        }
    }
    for (int i = 0; i <= N; ++i) imos[i] += geta;
    for (int i = 0; i <= N; ++i) imos[i+1] += imos[i];
    
    vector<long long> res = imos;
    for (int b = 1; b < DIV; ++b) {
        for (int i = 0; i < N; ++i) {
            int r = i % b;
            res[i] += sb[b][r];
        }
    }
    
    for (int i = 0; i < N; ++i) printf("%lld\n", res[i]);
}
accuracy: 1
time_ms: 200
memory_kb: 6896
final_rank: 5

code_snippet: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

ll sum[SIZE];

int main(){
  int n, m;
  ll suma = 0;
  map<pair<int,int>,int> mm;
  
  scanf("%d%d", &n,&m);

  for(int i=0;i<m;i++){
    int a, b;

    scanf("%d%d", &a,&b);
    suma += a;
    mm[make_pair(a,b)]++;
  }
  
  for(auto it : mm){
    int a = it.first.first;
    int b = it.first.second;
    int c = it.second;
    
    for(int i=b-a;i<=n;i+=b){
      if(i) sum[i] -= (ll)c * b;
    }
  }

  for(int i=0;i<n;i++){
    suma += m + sum[i+1];    
    printf("%lld\n",suma);
  }
  
  return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 9820
final_rank: 7

code_snippet: #include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<55)+1e9; // ~ 3.6 * 1e16
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
using T = tuple<Int,Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> &a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
template<class T>void prArr(T a,string s=" "){Int i=0;for(T t:a)cout<<(i++?s:"")<<t;cout<<endl;}

template<typename T>
class CumulativeSum{
public:
  int n;
  vector<T> sum;
  vector<T> A;
  int added;
  CumulativeSum():n(-1),added(0){}
  CumulativeSum(int n):n(n), sum(n+1), A(n+1),added(0){}
  CumulativeSum(const vector<T> &B):n(B.size()), sum(n+1), A(n+1),added(0){
    for(int i=1;i<=n;i++) sum[i] = sum[i-1] + B[i-1];
  }

  void apply(){
    for(int i=1;i<=n;i++) A[i] = A[i] + A[i-1];
    for(int i=1;i<=n;i++) A[i] = A[i] + A[i-1];
    for(int i=1;i<=n;i++) sum[i] = sum[i] + A[i-1];
    added = 0; A.clear(); A.resize(n+1);
  }

  //[l, r)にxを加算
  T add(int l, int r, T x){
    added = 1;
    assert(l <= r && 0 <= l && r <= n);
    A[l] = A[l] + x;
    A[r] = A[r] - x;
  }

  //[l, r)の和を得る
  T get(int l,int r){
    assert(l<=r && 0<=l && r<=n);
    if(added) apply();
    return sum[r] - sum[l];
  }
};

signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);
  Int N, M;
  cin>>N>>M;

  const Int limit = 500;
  CumulativeSum<Int> S(N+100);
  
  auto query1=[&](Int a, Int b){ //b >= limit
    assert(b >= limit);
    a %= b;
    Int l = 0, r = min(N, b - a - 1);
    S.add(l, l+1, a);
    S.add(l, r, 1);
    S.add(r, r+1, -(a+r));
    l = r + 1;
    r = min(N, r + b);
    a = 0;
    while(l < N){
      S.add(l, r, 1);
      S.add(r, r+1, -(r-l));
      l = r + 1;
      r = min(N, r + b);
    }
  };

  vector<vector<Int> > mem(limit, vector<Int>(limit, 0));
  auto query2=[&](Int a, Int b){ // b < limit
    assert(b < limit);
    a %= b;
    for(Int i=0;i<b;i++) mem[b][i] += (a+1 + i)%b;
  };
    
  for(Int i=0;i<M;i++){
    Int a, b;
    cin>>a>>b;
    (b >= limit)? query1(a, b):query2(a, b);
  }

  for(Int i=0;i<N;i++){
    Int ans = S.get(0, i+1);
    for(Int j=1;j<limit;j++) ans += mem[j][i%j];
    cout<<ans<<endl;
  }
  
  return 0;
}
accuracy: 1
time_ms: 640
memory_kb: 6280
final_rank: 6

code_snippet: #include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  Int n,m;
  cin>>n>>m;
  vector<Int> a(m),b(m);
  for(Int i=0;i<m;i++) cin>>a[i]>>b[i];

  const Int BS = 400;
  vector<Int> x(n,0);
  vector<vector<Int> > p(BS,vector<Int>(BS,0));
  vector<Int> d(n,0);
  Int f=0;
  
  for(Int i=0;i<m;i++){
    if(b[i]<BS){
      for(Int j=0;j<b[i];j++)
	p[b[i]][j]+=(a[i]+j+1)%b[i];
    }else{
      f++;
      d[0]+=a[i];
      for(Int j=b[i]-(a[i]+1);j<n;j+=b[i])
	d[j]+=-b[i];
    }
  }
  
  for(Int i=1;i<BS;i++)
    for(Int j=0;j<n;j++)
      x[j]+=p[i][j%i];

  for(Int j=0;j<n;j++){
    if(j) d[j]+=d[j-1];
    d[j]+=f;
    x[j]+=d[j];
  }
  
  for(Int i=0;i<n;i++) cout<<x[i]<<endl;
  return 0;
}
accuracy: 1
time_ms: 570
memory_kb: 7076
final_rank: 8

code_snippet: #include <bits/stdc++.h>
#define REP(i, a, n) for (ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

int main(void) {
  ll N, M;
  cin >> N >> M;
  vector<ll> A(M), B(M);
  REP(i, 0, M) cin >> A[i] >> B[i];

  map<pll, ll> p;
  REP(i, 0, M) p[pll(A[i], B[i])]++;

  vector<ll> x(N, M);
  for (auto q : p) {
    ll a = q.first.first, b = q.first.second, cnt = q.second;
    x[0] += a * cnt;
    for (ll j = b - a; j - 1 < N; j += b) {
      x[j - 1] -= b * cnt;
    }
  }

  REP(i, 0, N - 1) x[i + 1] += x[i];
  REP(i, 0, N) cout << x[i] << endl;
}
accuracy: 1
time_ms: 150
memory_kb: 11268
final_rank: 12

code_snippet: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:https://onlinejudge.u-aizu.ac.jp/services/room.html#ACPC2018Day2/problems/G>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */


int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    ll N,M; cin >> N >> M;
    vector<ll> A(M),B(M);
    for(int i = 0; i < M;i++) cin >> A[i] >> B[i];

    vector<ll> ans(N);
    for(int i = 1; i < N;i++) ans[i] = ans[i-1] + M;
    
    vector<ll> rm(N);
    ll sum = 0;
    for(int i = 0; i < M;i++){
        sum += (A[i] + 1)%B[i];
        
        ll ind = B[i] - ((A[i]+1)%B[i]);
        while(ind < N){
            rm[ind] += B[i];
            ind += B[i];
        }
    }
//    cout << sum << endl;
//    cout << ans << endl;
//    cout << rm << endl;
    
    cout << ans[0] + sum << endl;
    for(int i = 1; i < N;i++){
        rm[i] += rm[i-1];
        
        ans[i] = ans[i] + sum - rm[i];
        cout << ans[i] << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 1420
memory_kb: 5732
final_rank: 13