All about pruning and duplication removal. Took me several submissions to get it AC:
#include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> #include <unordered_map> using namespace std; #define BOUND (1000000007) int main() { // Get input int n, m; cin >> n >> m; vector<long long> A(n); for(int i = 0; i < n; i ++) cin >> A[i]; vector<long long> B(m); for(int i = 0; i < m; i ++) cin >> B[i]; vector<long long> C(m); for(int i = 0; i < m; i ++) cin >> C[i]; // unordered_map<int, long long> hm; for(int i = 0; i < m; i ++) { if(hm.find(B[i]) == hm.end()) { hm[B[i]] = C[i]; } else { hm[B[i]] *= C[i]; hm[B[i]] %= BOUND; } } // long long facOne = 1; for(auto &e: hm) { if(e.first == 1) { facOne *= e.second; facOne %= BOUND; continue; } int j = e.first - 1; while(j < n) { A[j] *= e.second; A[j] %= BOUND; j += e.first; } } // for_each(A.begin(), A.end(), [&](long long v){ v = (v * facOne) % BOUND; cout << v << " ";}); return 0; }
时间: 2024-12-28 20:53:25