URAL 1491. Unreal Story(区间染色, 数学啊)
2015-02-07 19:41
381 查看
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1491
You won't believe it, but once, in ancient times, there happened the following story. At a meeting of the Round Table, King Arthur stood up and said: “Let each knight sitting on my right not farther
than b places and not nearer than a places receive from me c gold coins.” If we number the knights from 1 to N counter-clockwise so that the knight sitting on Arthur's right is numbered 1 and the knight sitting on Arthur's
left is numbered N, then we have that the king gave c gold coins to the knights with numbers a, a + 1, …, b.
Having looked at Arthur's generous deed, the noble knights started to stand up one after another and tell their three numbers ai, bi, ci (1 ≤ i ≤ N).
After each of these utterances, the knights with numbers from ai to bi received ci gold
coins each from the king.
Since each knight was very noble, either ai > i or bi < i.
You task is to help the knights to learn how many gold coins each of them received.
The first line contains the number of King Arthur's knights N (2 ≤ N ≤ 100000). In the next line, there are integers a, b, and c, which the king said (1 ≤ a ≤ b ≤ N;
1 ≤ c ≤ 10000). Each of the next N lines contains three integers ai, bi, ci,
which the ith knight said (1 ≤ ai ≤ bi ≤ N; 1 ≤ ci ≤ 10000).
Output N numbers separated with a space. The ith number is the number of gold coins received by theith knight.
Problem Author: Alexander Toropov
Problem Source: XIII-th USU Junior Contest, October 2006
题意:
给出染色区间,求每个区间被染色次数!
代码如下:
You won't believe it, but once, in ancient times, there happened the following story. At a meeting of the Round Table, King Arthur stood up and said: “Let each knight sitting on my right not farther
than b places and not nearer than a places receive from me c gold coins.” If we number the knights from 1 to N counter-clockwise so that the knight sitting on Arthur's right is numbered 1 and the knight sitting on Arthur's
left is numbered N, then we have that the king gave c gold coins to the knights with numbers a, a + 1, …, b.
Having looked at Arthur's generous deed, the noble knights started to stand up one after another and tell their three numbers ai, bi, ci (1 ≤ i ≤ N).
After each of these utterances, the knights with numbers from ai to bi received ci gold
coins each from the king.
Since each knight was very noble, either ai > i or bi < i.
You task is to help the knights to learn how many gold coins each of them received.
Input
The first line contains the number of King Arthur's knights N (2 ≤ N ≤ 100000). In the next line, there are integers a, b, and c, which the king said (1 ≤ a ≤ b ≤ N;1 ≤ c ≤ 10000). Each of the next N lines contains three integers ai, bi, ci,
which the ith knight said (1 ≤ ai ≤ bi ≤ N; 1 ≤ ci ≤ 10000).
Output
Output N numbers separated with a space. The ith number is the number of gold coins received by theith knight.
Samples
input | output |
---|---|
4 2 3 2 2 4 1 3 4 1 1 2 1 1 1 1 | 2 4 4 2 |
7 1 7 1 2 3 4 3 5 3 1 2 1 5 7 4 2 4 10 3 4 2 1 6 3 | 5 19 23 19 11 8 5 |
Problem Source: XIII-th USU Junior Contest, October 2006
题意:
给出染色区间,求每个区间被染色次数!
代码如下:
#include <cstdio> #include <cstring> #include <cmath> int main() { int n; int aa, bb, cc; int a, b, c; int s[100017]; while(~scanf("%d",&n)) { memset(s,0,sizeof(s)); scanf("%d%d%d",&aa,&bb,&cc); s[aa]+=cc, s[bb+1]-=cc; for(int i = 0; i < n; i++) { scanf("%d%d%d",&a,&b,&c); s[a]+=c, s[b+1]-=c; } int ans = 0; ans+=s[1]; printf("%d",ans); for(int i = 2; i <= n; i++) { ans+=s[i]; printf(" %d",ans); } printf("\n"); } return 0; }
相关文章推荐
- ural 1019 Line Painting 线段树 区间染色
- POJ 2777——Count Color(线段树,区间染色+简单hash)
- ZOJ 1610 Count the Colors (线段树:区间染色set,整体查询)
- 连续区间覆盖染色问题 ------ SHUOJ 1716
- POJ 1436 Horizontally Visible Segments(线段树区间染色查询)
- URAL 1120. Sum of Sequential Numbers (数学)
- Ural 1303. Minimal Coverage / 最小区间覆盖
- ural 2032 Conspiracy Theory and Rebranding (数学水题)
- 【数学题】【网络流】风扇 blower ural1765
- 处理一个数是否落在一个数值范围里(a, b]里(区间左右括号符合数学定义)
- bzoj 2243: [SDOI2011]染色 线段树区间合并+树链剖分
- 【多校第9场】【组合数学】【区间dp】【Expression】
- URAL 2070 Interesting Numbers(数学)
- 数学闭区间和开区间的区别是什么
- 数学之路-数据分析进阶-区间预计与如果检验(2)
- URAL 1727. Znaika's Magic Numbers(数学 vector)
- 【bzoj2243】[SDOI2011]染色 树链剖分 (区间合并处理)
- ZOJ 1610【线段树区间染色】
- ZOJ 1610 Count the Colors(线段树——区间更新)(成段染色)
- codevs 1191 树轴染色 线段树区间定值,求和