Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
求救,错哪了?#include<iostream> #define N 500000 using namespace std; struct node { int l,r,col; bool si; }nd[N]; int ans; void build(int a,int b,int v) { nd[v].l =a; nd[v].r=b; nd[v].col=1; nd[v].si=1; if(nd[v].l<nd[v].r) { int mid=(nd[v].l+nd[v].r)>>1; build(a,mid,2*v); build(mid+1,b,2*v+1); } } void insert(int a,int b,int v,int q) { if(nd[v].l==nd[v].r) { nd[v].col=(1<<(q-1)); return; } int mid=(nd[v].l+nd[v].r)>>1; if(a<=mid)insert(a,b,2*v,q); if(b>mid)insert(a,b,2*v+1,q); nd[v].col =nd[2*v].col | nd[2*v+1].col; if(nd[2*v].col==nd[2*v+1].col)nd[v].si=1; else nd[v].si=0; } void search(int a,int b,int v) { if(nd[v].si) { ans |= nd[v].col; return; } if(nd[v].l>=a&&nd[v].r<=b) { ans |=nd[v].col; return; } int mid=(nd[v].l+nd[v].r)>>1; if(a<=mid) search(a,b,2*v); if(b>mid) search(a,b,2*v+1); } int main() { int L,T ,O; int m,n,c; char ch; scanf_s("%d %d %d",&L,&T ,&O); build(1,L,1); while(O--) { cin>>ch; if(ch=='C') { scanf_s("%d %d %d",&m,&n,&c); if(m<n)insert(m,n,1,c); else insert(n,m,1,c); } else { ans=0; int an=0; int bit=1; scanf_s("%d %d",&m,&n); if(m<n)search(m,n,1); else search(n,m,1); while(bit<=ans) { if(ans&bit)an++; bit<<=1; } printf_s("%d\n",an); } } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator