The road of calculation (knockout car)

Source: Internet
Author: User

The racing race has become more and more popular in Pandora. But their game is not the same as our usual: N-Cars compete on a long straight track. The speed of each car is 1m/s, and the entire track is marked with coordinates at every metre.

In racing cars, I moved from ai to bI from 0 seconds onwards. After reaching Bi , I move back from BI to ai . Cycle.

Another garlic fungus! Originally this is the garlic fungus is playing a mobile phone game. Garlic fungus can put down TNT in some places to blow up some cars. Because he has a m problem. The question J is: how many cars are there in the TJ moment between xi and yi ?

Your task is to answer the question of Meng garlic.

Input

The first line of input contains two numbers n and M (1≤n, m≤1000), respectively, representing the number of racing cars and the number of garlic problems in the race.

i , Bi (0≤ai , Bi  ≤109 , Ai  != bi ", respectively, representing the starting and ending points of the racing I.

j , Yj , Tj (0≤xj  ≤yj  ≤109 , 0≤tj  ≤109 ", respectively, representing the left and right coordinate boundaries of question J and the time of inquiry.

Output

The output has a total of m rows, each with an integer representing the answer to the corresponding m question.

Example 1

Input:

5 50 10 22 33 54 50 5 00 1 20 2 12 5 22 5 3

Output:

51243
#include <stdio.h>const int N = 1005;struct car{int l,r,t,flag;}    Node[n];int Main () {int n,m,ans,l,r,t; while (scanf ("%d%d", &n,&m) >0) {for (int i=0; i<n; i++) {scanf ("%d%d", &node[i].l,&nod            E[I].R);            if (NODE[I].L&LT;=NODE[I].R) node[i].flag=0;                else{node[i].flag=1;                int tmp=node[i].l;                NODE[I].L=NODE[I].R;            node[i].r=tmp;        } NODE[I].T=NODE[I].R-NODE[I].L;            } while (m--) {scanf ("%d%d%d", &l,&r,&t);            ans=0;                for (int i=0; i<n; i++) {int tmp=t/node[i].t+node[i].flag;                int res=t%node[i].t;                int Loc;                if (tmp&1) loc=node[i].r-res;                else Loc=node[i].l+res;            if (loc>=l&&loc<=r) ans++; } printf ("%d\n", ans); }    }}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The road of calculation (knockout car)

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.