版本比较
题解:P15359 「WYZOI R2」春运
正文
增加 7 行删除 7 行
15 行未改动1617181920202122232420 行未改动454647484949505152535455565556575859606162626364656617 行未改动848586878888899091928 行未改动10110210310410510510610710810910 行未改动15 行未改动int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin>>d>>n>>m>>t; for (int i = 0; i < n; i++){ cin>>a[i]; vt.push_back(a[i]);20 行未改动
cout<<ans; return 0; }
for (int i = 0; i < t; i++){ if (i % m == 0){ int fr = vt.back(); vt.erase(vt.end() - 1); vt.insert(vt.begin(), fr); } }
ans += vt[i % n]; if (ans >= d) ans %= d; }
cout<<ans;
return 0;}```但是用这种方法会直接导致大数据量 TLE, 所以我们需要**优化**。17 行未改动int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin>>d>>n>>m>>t; for (int i = 0; i < n; i++){ cin>>a[i]; vt.push_back(a[i]);8 行未改动 period_sum += a[index]); period_sum %= d; }
ll cycles = t / cyc_len;//循环数 ll remain = t % cyc_len;//剩余数 ll ans = (period_sum * (cycles%d)) % d;
10 行未改动