Submission #1124181

#TimeUsernameProblemLanguageResultExecution timeMemory
1124181mychecksedadTrains (BOI24_trains)C++20
24 / 100
136 ms50808 KiB
/* Author : Mychecksdead  */
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
const int N = 1e6+100, M = 1e5+10, K = 52, MX = 30, S = 300;


ll n, d[N], x[N];
ll dp[N], A[S][S];
vector<int> to[N], rem[N];
void solve(){
  cin >> n;
  for(int i = 1; i <= n; ++i){
    cin >> d[i] >> x[i];
    if(d[i] >= S){
      int cur = i;
      for(int j = 1; j <= x[i] && cur + d[i] <= n; ++j){
        cur += d[i];
        to[cur].pb(i);
      }
    }else{
      if(d[i] != 0 && x[i] != 0)
        rem[min(n+1, i+d[i]*x[i])].pb(i);
    }
  }
  ll ans = 0;
  for(int i = 1; i <= n; ++i){
    dp[i] = (i == 1);
    for(int j: to[i]){
      dp[i] += dp[j];
      if(dp[i] >= MOD) dp[i] -= MOD;
    }
    for(int j = 1; j < S; ++j){
      dp[i] += A[j][i % j];
    }
    for(int j: rem[i]){
      A[d[j]][j % d[j]] -= dp[j];
      if(A[d[j]][j % d[j]] < 0) A[d[j]][j % d[j]] += MOD;
    }
    if(d[i] != 0 && d[i] < S && x[i] != 0){
      A[d[i]][i % d[i]] += dp[i];
      if(A[d[i]][i % d[i]] >= MOD) A[d[i]][i % d[i]] -= MOD;
    }
    ans += dp[i];
    if(ans >= MOD) ans -= MOD;
  }
  cout << ans;

}


int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  int tt = 1, aa;
  // freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
  while(tt--){
    solve();
    en;
  }
  cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n";
  return 0;
} 
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...