Bjwc2008 Qin Teng and teaching evaluation

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.