# ZJ a693. 吞食天地 [ZJ 693](https://zerojudge.tw/ShowProblem?problemid=a693) 先處理儲存前綴和,可以快速查表算出區間和 ## code ``` python= #include <iostream> using namespace std; int main() { int n,m; while (cin >> n >> m) { int nx[n+1]; nx[0] = 0; for (int i=1; i<n+1; i++) { cin >> nx[i]; nx[i] +=nx[i-1]; //前綴和 } for (int j=0; j<m; j++) { int s,e; cin >> s >> e; cout << nx[e] - nx[s-1] << endl; } } return 0; } ``` ###### tags: `c++` `前綴和`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up