版本比较
题解:P15359 「WYZOI R2」春运
正文
增加 7 行删除 7 行
15 行未改动16171819202122232420 行未改动4546474849505152535455565758596061626364656617 行未改动8485868788899091928 行未改动10110210310410510610710810910 行未改动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 行未改动15 行未改动16171819202122232420 行未改动4546474849505152535455565758596061626364656617 行未改动8485868788899091928 行未改动10110210310410510610710810910 行未改动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 行未改动