luyencode / comments

Server lưu trữ bình luận trên Luyện Code
https://luyencode.net
6 stars 3 forks source link

https://oj.luyencode.net/problem/SUMXY #836

Open utterances-bot opened 1 year ago

utterances-bot commented 1 year ago

Chi tiết bài tập - Luyện Code Online

https://oj.luyencode.net/problem/SUMXY

danh2006 commented 1 year ago

Đây là lời giải của mình đã AC. Nếu bạn đã cố gắng mà chưa làm được thì có thể tham khảo lời giải của mình.

Xem code AC

#include #define ll long long using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll n, m; cin >> n >> m; ll a[n]; for(ll i=1;i<=n;i++){ cin >> a[i]; } ll prefix[n+1]={0}; for(ll i=1;i<=n;i+=1){ prefix[i]=prefix[i-1]+a[i]; } while(m--){ ll a, b; cin >> a >> b; cout << prefix[b]-prefix[a-1] << endl; } }

sseu18042004 commented 1 year ago

hint :)) MỌI NGƯỜI ĐỂ Ý LÀ DÙNG LONG LONG INT NHÉ, TRÁNH BỊ TRÀN SỐ