"POJ3657" "Usaco-Jan Gold" 1.Haybale guessing two-point answer, and check set check

Source: Internet
Author: User

Test instructions

The input n, m indicates that the sequence length is n and there is an ordered limit of M-bar {l,r,x}.

Limit: The minimum value of all the l~r between the two is X.

Asked the first few restrictions begin to appear contradictory, do not appear output "0".


Exercises

First of all, the problem is quite strong, the normal solution is a bit difficult, it may be translated into two answers.

We have a two-point "answer", that is, a contradiction in the ANS clause.


Consider that if a limit s is contained by another restricted SEG, and the X of the SEG limit is larger than s.x,

So that means

①[SEG.L,SEG.R] The minimum value between seg.x

②[s. L,s r] The minimum value is S. x

③s.x < seg.x

This is a contradictory situation and is the only contradiction, that is, there is no other contradictory situation.


Then we'll be able to check the anger.

This time involves an idea:

We can sort the "limit" in descending order of the current check with the keyword x,

It then records whether a node (or interval) is overwritten.


The segment tree is obviously possible. (... It's also obvious that it takes several K constants to optimize

So here's a tip:

We can maintain a f[i]=j to show that the interval of j+1 to I is covered.

Then the averaging is seemingly a large constant O (n), in short, very fast is, I have not discretized on the high speed. ... (although it is not a bottleneck


For this time complexity analysis if who can prove to be N*LOGN, welcome message to face.


Code:

#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define N 1001000# Define M 30000#define inf 0x3f3f3f3fusing namespace std;/*struct lsh{int x,note;bool Flag;bool operator < (const LSH &A Mp;a) Const{return x<a.x;}} Lsh[m<<1];*/struct lux{int L,r,x;bool operator < (const Lux &a) Const{return x>a.x;}} Q[m],q[m];int n,m,f[n];int stk[n],top;int Find (int x) {top=0;while (f[x]!=x) stk[++top]=x,x=f[x];while (top) f[stk[ Top--]]=x;return x;} BOOL Check (int mid) {int i,j,k,t;int l,r,l,r;for (i=1;i<=n;i++) f[i]=i;for (i=1;i<=mid;i++) Q[i]=q[i];sort (q+1,q+ MID+1); for (i=1;i<=mid;i=j+1) {l=l=q[i].l,r=r=q[i].r;for (j=i;j<mid&&q[j+1].x==q[j].x;) {j + +; L=min (L,Q[J].L), R=max (R,Q[J].R), L=max (L,Q[J].L), R=min (R,Q[J].R);} if (Find (r) <l) return 0;for (T=r;k=find (t), k>=l;t=k-1) f[k]=l-1;} return 1;} int main () {//freopen ("test.in", "R", stdin), int i,j,k;int l,r,mid,ans;scanf ("%d%d", &n,&m); for (i=1;i<=m;i + +) scanf ("%d%d%d", &q[i].l,&Amp q[i].r,&q[i].x); L=1,r=m,ans=0;for (i=1;i<=20&&l<=r;i++) {mid=l+r>>1;if (check (mid)) l=mid+ 1;else ans=mid,r=mid-1;} printf ("%d\n", ans); return 0;}


"POJ3657" "Usaco-Jan Gold" 1.Haybale guessing two-point answer, and check set check

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.