codeforces 589 D - Boulevard

D - Boulevard

Time Limit:2000MS     Memory Limit:524288KB     64bit IO Format:%I64d & %I64u

Submit Status Practice CodeForces 589D

Description

Welcoming autumn evening is the best for walking along the boulevard and n people decided to do so.

The boulevard can be represented as the axis Ox. For every person there are three parameters characterizing the behavior: ti, si, fi — the moment of time when the i-th person starts walking, the start point and the end point of the walk respectively. Each person moves in a straight line along the boulevard from si to fi with a constant speed of either 1 or  - 1 depending on the direction.

When the i-th person appears on the boulevard at the point si she immediately starts walking towards the point fi.

If two or more persons meet at the boulevard (they are at the same point at the same time, no matter which directions they are going) they all greet each other. Like in the normal life, every pair of people greet each other at most once.

You task is to calculate for every person how many people she greets while walking along the boulevard.

Please, pay attention to the fact that i-th person may meet and greet any other person at points si and fi. After a person achieves the destination point fi she moves out of the boulevard and cannot greet anyone else. The same rule applies to the start of the walk: a person cannot greet anyone until she appears on the boulevard.

Input

In the first line there is an integer n(2 ≤ n ≤ 1000) — the number of people who decided to go for a walk.

The following n lines contain parameters for n people. In the i-th line there are three positive integers ti, si, fi(1 ≤ ti, si, fi ≤ 106,  si ≠ fi), where ti, si, fi — the moment of time when the i-th person starts walking, the start point and the end point of the walk respectively.

Output

The single line of the output should contain a sequence of n integers r1, r2, ..., rn separated by a space, where ri denotes the number which the i-th person greets other people while walking along the boulevard.

Sample Input

Input

31 1 105 8 29 9 10

Output

2 1 1 

Input

33 2 44 3 43 6 4

Output

2 2 2 

傻逼模拟题。。。。我的思路是先处理出方向啊,运行的时间啊,然后在线段上消失的时刻。按照出现的时间升序排序。

然后分别考虑同向和异向(错误得以为同正和同反可以一起考虑。。。。这是WA了好多发的根源。。。。)需要注意的地方见注释吧。。。。主要就是分好情况以及判断的时候是否需要在同一时刻。


  1 /*************************************************************************
  2     > File Name: code/hust/20151025/DDD.cpp
  3     > Author: 111qqz
  4     > Email: [email protected]
  5     > Created Time: 2015年10月26日 星期一 20时16分47秒
  6  ************************************************************************/
  7
  8
  9
 10 #include<iostream>
 11 #include<iomanip>
 12 #include<cstdio>
 13 #include<algorithm>
 14 #include<cmath>
 15 #include<cstring>
 16 #include<string>
 17 #include<map>
 18 #include<set>
 19 #include<queue>
 20 #include<vector>
 21 #include<stack>
 22 #include<cctype>
 23
 24 #define yn hez111qqz
 25 #define j1 cute111qqz
 26 #define ms(a,x) memset(a,x,sizeof(a))
 27 using namespace std;
 28 const int dx4[4]={1,0,0,-1};
 29 const int dy4[4]={0,-1,1,0};
 30 typedef long long LL;
 31 typedef double DB;
 32 const int inf = 0x3f3f3f3f;
 33 const int N=1E3+7;
 34 int n;
 35
 36 struct Q
 37 {
 38     int t,s,f;
 39     int fint;
 40     int cost;
 41     int id;
 42     int dir;
 43
 44 }q[N];
 45
 46 int cnt[N];
 47
 48
 49 bool cmp(Q a,Q b)
 50 {
 51     return a.t<b.t;
 52 }
 53 int main()
 54 {
 55   #ifndef  ONLINE_JUDGE
 56    freopen("in.txt","r",stdin);
 57   #endif
 58
 59    scanf("%d",&n);
 60    for ( int i = 0 ; i < n ;i++)
 61     {
 62     scanf("%d %d %d",&q[i].t,&q[i].s,&q[i].f);
 63     q[i].id= i;
 64     if (q[i].s<q[i].f)
 65     {
 66         q[i].dir = 1;
 67         q[i].cost = q[i].f-q[i].s;
 68     }
 69     else
 70     {
 71         q[i].dir = 0;
 72         q[i].cost = q[i].s - q[i].f;
 73     }
 74     q[i].fint = q[i].t + q[i].cost;
 75     }
 76
 77     sort(q,q+n,cmp);
 78     ms(cnt,0);
 79     for ( int i = 0 ; i < n ; i++)
 80     for ( int j = i+1 ;  j < n ; j++)
 81     {
 82         if (q[i].dir==q[j].dir)
 83         {
 84     //    if (q[i].fint<q[j].t) continue;
 85     //    cout<<"i:"<<q[i].id<<" j:"<<q[j].id<<endl;
 86         if (q[j].t-q[i].t+q[i].s==q[j].s&&q[i].fint>=q[j].t&&q[i].dir==1)
 87         {
 88             cnt[q[i].id]++;
 89             cnt[q[j].id]++;
 90         }
 91         if (q[i].s-(q[j].t-q[i].t)==q[j].s&&q[i].fint>=q[j].t&&q[i].dir==0) //wa了31次之后
 92                                             //发现。。。除了写错之外。
 93                                             //只有两个地方没考虑清楚。。
 94                                             //一个是误以为同方向()的可以一块考虑。
 95                                             //实际上不能。因为这个wa了五六次。
 96                                                                 //另一个是相向判相遇的时候,条件要判
 97                                                                 //同一时刻的。。。比如j出现时,i在q[i].s+(q[j].t-q[i].s)(以i正向为例)。。。。
 98                                                                 //热泪盈眶。。。。
 99                                                                 //WA 了这么多次还有一个原因是。。。忘记前后的答案是相互影响的。。。我把前面修改后反而对的点更少了。。写成错的反而对得多
100                                                                 //差点怀疑人生了都。。。其实是因为后面还有写错。。。前面多算。。后面少算。。答案碰巧对了而已2333
101         {
102             cnt[q[i].id]++;
103             cnt[q[j].id]++;
104         }
105         }
106         else
107         {
108
109         if (q[i].dir==1)
110         {
111             int limt = min(q[i].fint,q[j].fint);
112             int nowi = q[i].s+(limt-q[i].t);
113             int nowj = q[j].s-(limt-q[j].t);
114     //        cout<<"limt:"<<limt<<endl;
115     //        cout<<"i:"<<q[i].id<<" j:"<<q[j].id<<"nowi:"<<nowi<<" nowj:"<<nowj<<endl;
116             if (nowi>=nowj&&q[i].s+(q[j].t-q[i].t)<=q[j].s)
117             {
118             cnt[q[i].id]++;
119             cnt[q[j].id]++;
120             }
121         }
122         else
123         {
124             int limt = min(q[i].fint,q[j].fint);
125             int nowi = q[i].s-(limt-q[i].t);
126             int nowj = q[j].s+(limt-q[j].t);
127     //        cout<<"lim:"<<limt<<endl;
128     //        cout<<"ii:"<<q[i].id<<" j:"<<q[j].id <<"nowi:"<<nowi<<" nowj"<<nowj<<endl;
129             if (nowj>=nowi&&q[i].s-(q[j].t-q[i].t)>=q[j].s)
130             {
131             cnt[q[i].id]++;
132             cnt[q[j].id]++;
133             }
134         }
135         }
136     }
137     for ( int i = 0 ; i < n ; i++)
138     {
139     if (i!=n-1)
140     {
141         printf("%d ",cnt[i]);
142     }
143     else
144     {
145         printf("%d\n",cnt[i]);
146     }
147     }
148
149
150  #ifndef ONLINE_JUDGE
151   fclose(stdin);
152   #endif
153     return 0;
154 }

时间: 2024-09-29 11:31:16

codeforces 589 D - Boulevard的相关文章

codeforces 589 I - Lottery(水)

I - Lottery Time Limit:2000MS     Memory Limit:524288KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 589I Description Today Berland holds a lottery with a prize — a huge sum of money! There are k persons, who attend the lottery

codeforces 589 G - Hiring(模拟?)

G - Hiring Time Limit:4000MS     Memory Limit:524288KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 589G Description The head of human resources department decided to hire a new employee. He created a test exercise for candidat

CodeForces 589 Email Aliases (匹配,水题)

题意:给定于所有的邮箱,都是由[email protected]这样的形式构成,而且字符都是不区分大小写的. 我们有一种特殊类型的邮箱——@bmail.com, 这种邮箱除了不区分大小写外—— 1,'@'之前的'.',有等同于无 2,'@'之前的第一个'+'之后的字符可以忽略不计 然后其他字符相同的被认定为邮箱相同. 现在给你 n 个邮箱,让你输出每个邮箱出现的次数与所有这个邮箱的原始串. 析:没什么好说的,就是先判断不是@bmail.com,然后再按要求去点,去+和@之间的值,然后一个一个的比

Codeforces Round #589 (Div. 2)-E. Another Filling the Grid-容斥定理

Codeforces Round #589 (Div. 2)-E. Another Filling the Grid-容斥定理 [Problem Description] 在\(n\times n\)的格子中填入\([1,k]\)之间的数字,并且保证每一行至少有一个\(1\),每一列至少有一个\(1\),问有多少种满足条件的填充方案. [Solution] 令\(R[i]\)表示为第\(i\)行至少有一个\(1\)的方案数,\(C[i]\)表示第\(i\)列至少有一个\(1\)的方案数.则题目要

Codeforces Round #589 (Div. 2) B——B. Filling the Grid

Suppose there is a h×wh×w grid consisting of empty or full cells. Let's make some definitions: riri is the number of consecutive full cells connected to the left side in the ii-th row (1≤i≤h1≤i≤h). In particular, ri=0ri=0 if the leftmost cell of the 

Codeforces Round #589 (Div. 2) (e、f没写)

https://codeforces.com/contest/1228/problem/A A. Distinct Digits 超级简单嘻嘻,给你一个l和r然后寻找一个数,这个数要满足的条件是它的每一位的数字不相同,找出满足要求的最小的那个数输出,没有找到就输出-1: 1 #include<bits/stdc++.h> 2 using namespace std; 3 bool check(int n){ 4 int vis[15]={0}; 5 while(n){ 6 if(!vis[n%

Codeforces Round #589 (Div. 2) A. Distinct Digits

链接: https://codeforces.com/contest/1228/problem/A 题意: You have two integers l and r. Find an integer x which satisfies the conditions below: l≤x≤r. All digits of x are different. If there are multiple answers, print any of them. 思路: 水题. 代码: #include

Codeforces Round #589 (Div. 2) - A

题目大意:给定一个闭区间,问这个区间内有没有满足各数位数字不相等的数,有的话输出任意一个,没有的话输出 -1. #include <bits/stdc++.h> #include <bitset> using namespace std; #define mp(x, y) make_pair(x,y) #define mset(a, n) memset(a, n, sizeof(a)) #define forn(i, n) for (int i = 0; i < (n); i

Codeforces Round #589 (Div. 2) - C

题目大意:$prime(x)$ 代表 $x$ 的质因数的集合. $g(x, p)$ 代表 $p^k$ 的最大值, $k$ 为整数,并且 $x$ 可以被 $p^k$ 整除. $f(x, p)$ 代表 对于 $prime(x)$ 中的每一个 $x$ 的 $g(x, p)$ 值. 现在给定 $x, n$ 求 $f(x, 1) * f(x, 2) * ... *f(x, n) mod (10^9 + 7)$ 的值. 思路:对于 $x$ 进行质因数分解,分别考虑每一个 $prime(x)$ 对答案做出的贡