Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:过了这个,基本就不会WA了,还有注意A可能大于B

Posted by 527554192 at 2010-08-02 08:57:09 on Problem 2777
In Reply To:Re:过了这个,基本就不会WA了,还有注意A可能大于B Posted by:yuest at 2009-08-24 19:59:01
我还是wa了
#include<iostream>
#include<stdlib.h>
using namespace std;
struct node
{
       int l,r,c;
}tree[4000000];
int tot(0);
bool pos[100];
void build(int l,int r,int s)
{

     tree[s].l=l;
     tree[s].r=r;
     tree[s].c=1;
   //   cout<<tree[s].l<<" "<<tree[s].r<<" "<<s<<" "<<endl;
     if(tree[s].l==tree[s].r)
     {
        return ;
     }
     int m=(l+r)/2;
     build(l,m,s*2);
     build(m+1,r,s*2+1);
}
void ins(int le,int ri,int c,int  s)
{
    // cout<<tree[s].l<<" "<<tree[s].r<<" "<<tree[s].c<<" "<<le<<" "<<ri<<endl;
     if((tree[s].l==le)&&(tree[s].r==ri))
     {
        tree[s].c=c;
        return ;
     }
     if((tree[s].c==-1)&&(tree[s*2].c==tree[s*2+1].c))
     {
        tree[s].c=tree[s*2].c;
     }
     if(tree[s].c!=-1)
     {
         tree[s*2].c=tree[s].c;
         tree[s*2+1].c=tree[s].c;
     }
     tree[s].c=-1;
     int m=(tree[s].l+tree[s].r)>>1;
    // cout<<m<<endl;
     if(ri<=m)
     {     //cout<<"is1"<<endl;
            ins(le,ri,c,s*2);

     }
     else
     if(le>m)
     {
           //  cout<<"is 2"<<endl;
              ins(le,ri,c,s*2+1);
     }
     else
     {
         ins(le,m,c,s*2);
         ins(m+1,ri,c,s*2+1);
     }
}
void  su(int  l,int r,int s)
{
    // cout<<l<<" "<<r<<" "<<tree[s].l<<" "<<tree[s].r<<"is pos [s]         "<<tree[s].c<<endl;

     //system("pause");
     if(tree[s].l==l&&tree[s].r==r&&tree[s].c!=-1)
     {
         // cout<<l<<" "<<" "<<r<<"is pos [s]    ok     "<<tree[s].c<<endl;
          pos[tree[s].c]=true;
        //  system("pause");
          return ;
     }
     int m=(tree[s].l+tree[s].r)>>1;
     if(r<=m)
     {
       //  cout<<"go left "<<endl;
         su(l,r,s*2);
     }
     else
     if(l>m)
     {
        // cout<<"go right"<<endl;
         su(l,r,s*2+1);
     }
     else
     {
        // cout<<"go ledt and right"<<endl;
         su(l,m,s*2);
         su(m+1,r,s*2+1);
     }
}
int  main ()
{
          int l,t,o,le,ri,co,to;
          char s[2];
          cin>>l>>t>>o;
         // cout<<l<<endl;
          build(1,l,1);
          while(o--)
          {

                    cin>>s;
                    if(s[0]=='C')
                    {
                         cin>>le>>ri>>co;
                         if(le>ri)
                         {
                                  to=le;
                                  le=ri;
                                  ri=to;
                         }
                      //   cout<<le<<" "<<ri<<" "<<co<<endl;
                         ins(le,ri,co,1);
                      //   cout<<le<<" "<<ri<<" "<<co<<endl;
                      //  for(int i=1;i<=((1<<l)-1);i++)
                       // {     cout<<tree[i].l<<" "<<tree[i].r<<" "<<i<<" "<<tree[i].c<<endl;
                       // }
                       // system("pause");
                    }
                    else
                    {   tot=0;
                        for(int i=1;i<=t;i++)
                        {
                              pos[i]=false;
                        }
                        cin>>le>>ri;
                        if(le>ri)
                         {
                                  to=le;
                                  le=ri;
                                  ri=to;
                         }
                      //   for(int i=1;i<=(l*2)-1;i++)
                        // {     cout<<tree[i].l<<" "<<tree[i].r<<" "<<i<<" "<<tree[i].c<<endl;
                         //}
                        su(le,ri,1);
                       // cout<<pos[1]<<"is pos 1"<<endl;
                        for(int i=1;i<=t;i++)
                        {
                                if(pos[i])
                                tot++;
                        }
                        cout<<tot<<endl;
                    }
          }
     // system("pause");
     return 0;
}


Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator