#include template class modint { using u64 = std::uint_fast64_t; public: u64 v; constexpr modint(const u64 x = 0) noexcept : v(x % mod) {} constexpr modint operator+(const modint rhs) const noexcept { return modint(*this) += rhs; } constexpr modint operator-(const modint rhs) const noexcept { return modint(*this) -= rhs; } constexpr modint operator*(const modint rhs) const noexcept { return modint(*this) *= rhs; } constexpr modint operator/(const modint rhs) const noexcept { return modint(*this) /= rhs; } constexpr modint &operator+=(const modint rhs) noexcept { v += rhs.v; if (v >= mod) v -= mod; return *this; } constexpr modint &operator-=(const modint rhs) noexcept { if (v < rhs.v) v += mod; v -= rhs.v; return *this; } constexpr modint &operator*=(const modint rhs) noexcept { v = v * rhs.v % mod; return *this; } constexpr modint &operator/=(modint rhs) noexcept { u64 exp = mod - 2; while (exp != 0) { if (exp % 2 != 0) *this *= rhs; rhs *= rhs; exp /= 2; } return *this; } }; #include #include #include int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); using mint = modint<1000000007>; int k, n, m; std::cin >> k >> n >> m; std::vector a(k), c(k); for (auto &e : a) { std::cin >> e.v; } for (auto &e : c) { std::cin >> e.v; } std::reverse(c.begin(), c.end()); // a_{n + k} まで計算する a.resize(k + n, mint(0)); for (int i = 0; i < n; ++i) { mint &t = a[i + k]; for (int j = 0; j < k; ++j) { t += a[i + j] * c[j]; } } auto add = std::vector(n + 1, std::vector()); auto sub = std::vector(n + 1, std::vector()); for (int i = 0; i < m; ++i) { int l, r; std::cin >> l >> r; add[l].push_back(0); sub[r].push_back(r - l); } auto s = std::vector(k, mint(0)); for (int i = 0; i < n; ++i) { // s を 1 つ進める mint t = 0; for (int j = 0; j < k; ++j) { t += s[j] * c[j]; } s.erase(s.begin()); s.push_back(t); for (int l : add[i]) { for (int j = 0; j < k; ++j) { s[j] += a[l + j]; } } for (int l : sub[i]) { for (int j = 0; j < k; ++j) { s[j] -= a[l + j]; } } std::cout << s[0].v << "\n"; } }