解题思路:
参考代码:
#include<bits/stdc++.h> using namespace std; const int SIZE = 100211; int BIT[SIZE]; int total; void updata(int pos, int V) { while (pos <= total) { BIT[pos] += V; pos += pos & (-pos); } } int query(int pos) { int ans = 0; while(pos){ ans += BIT[pos]; pos -= pos & (-pos); } return ans; } int main() { int que, L, R, V; scanf("%d%d", &total, &que); while (que--) { scanf("%d%d%d", &L, &R, &V); updata(L, V); updata(R + 1, -V); } for (int pos = 1; pos <= total; pos++) printf("%d ", query(pos)); }
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题8.8 (C语言代码)浏览:853 |
Hello, world! (C语言代码)浏览:714 |
模拟计算器 (C++代码)浏览:800 |
格式化数据输出 (C语言代码)浏览:811 |
C语言程序设计教程(第三版)课后习题10.2 (C语言代码)浏览:535 |
A+B for Input-Output Practice (I) (C语言代码)浏览:570 |
C语言程序设计教程(第三版)课后习题6.9 (C语言代码)浏览:479 |
众数问题 (C语言代码)浏览:621 |
IP判断 (C++代码)浏览:746 |
C语言程序设计教程(第三版)课后习题7.2 (C++代码)浏览:426 |