Portal
This is a binary answer ...... I guess it's hard to see that this is the second answer ......
The question requires finding out which of the following is an odd number of teachers in the sequence.
This question is amazing. We often struggle with how to save so many points and how to handle the teacher's position. But these are not the key to solving the problem. We should pay attention to the fact that there is only one odd number of teachers in the sequence. In this case, we can know the points that contain this position, the prefix and number of its teachers must be odd. The prefix and number of vertices that do not contain this position must be an even number.
So we can divide this location into two points !! Then we only need to ask how many teachers we have. This can be determined by O (N), because the teacher's position is an arithmetic difference series, you can directly calculate the number of teachers that each interval has contributed to the prefix.
Then we have finished ...... I cannot think of this question ......
#include<cstdio>#include<algorithm>#include<cstring>#include<iostream>#include<cmath>#include<set>#include<queue>#define rep(i,a,n) for(int i = a;i <= n;i++)#define per(i,n,a) for(int i = n;i >= a;i--)#define enter putchar(‘\n‘)using namespace std;typedef long long ll;const int M = 200005;const int N = 1005;const int INF = 2147483647;int read(){ int ans = 0,op = 1; char ch = getchar(); while(ch < ‘0‘ || ch > ‘9‘) { if(ch == ‘-‘) op = -1; ch = getchar(); } while(ch >= ‘0‘ && ch <= ‘9‘) { ans *= 10; ans += ch - ‘0‘; ch = getchar(); } return ans * op;}struct seg{ ll s,e,d;}a[M];int T,n,pos;ll L,R;int calc(ll x){ int cur = 0; rep(i,1,n) { if(x < a[i].s) continue; cur += (min(x,a[i].e) - a[i].s) / a[i].d + 1; } //printf("#%d %d\n",x,cur); return cur;} bool check(int x){ return calc(x) & 1;}int main(){ T = read(); while(T--) { n = read(),R = 0,pos = 0; rep(i,1,n) a[i].s = read(),a[i].e = read(),a[i].d = read(),R = max(R,a[i].e); L = 1; while(L <= R) { ll mid = (L+R) >> 1; if(check(mid)) pos = mid,R = mid - 1; else L = mid + 1; } if(!pos) printf("Poor QIN Teng:(\n"); else { int cnt = calc(pos) - calc(pos-1); printf("%d %d\n",pos,cnt); } } return 0;}
Bjwc2008 Qin Teng and teaching evaluation