1. 程式人生 > >【中山市選2013】花瓶

【中山市選2013】花瓶

Description

小愛整天收到花。她有N個花瓶標號從0到N-1。如果她收到F朵花,她會選擇一個花瓶A,嘗試去放花進去那個花瓶。如果那個花瓶已經有花,她就順序地找下一個,直到所有花都放完或者後面沒有花瓶了。有時她會清理花瓶,把花瓶A到B(A<=B)之間的花全扔了。

Input

第一行兩個整數N和M代表花瓶數和運算元。

然後M行每行第一個數字是K(1或2)。如果K是1,那麼再輸入A和F,如果K是2,那麼輸入A和B,含義如上所述。

Output

每個操作輸出一行。

對於操作1,輸出成功放花的第一個位置和最後一個位置,如果一朵花都沒放,輸出‘Can not put any one.’。

對於操作2,輸出扔了多少花。

Sample Input

10 5

1 3 5

2 4 5

1 1 8

2 3 6

1 8 8

Sample Output

3 7

2

1 9

4

Can not put any one.

Data Constraint

對於40%的資料,有1≤N,M≤100。

對於100%的資料,有1≤N,M≤50000。

思路:

一看就是線段樹,但我是蒟蒻,不會打。。。233 。。。
結果暴力睡了90分
然後加了O3優化,AC了。。。

程式碼:

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std; bool a[55555]; __attribute__((optimize("-O3"))) int main() { int n=0,m=0; scanf("%d%d",&n,&m); memset(a,0,sizeof(a)); for(int i=1; i<=m; i++) { int x=0,y=0,t=0,xx=0; scanf("%d%d%d",&t,&x,&y); if(t==1) { bool
f=0; int p=y; while(p>0 && x<=n-1) { if(!a[x]) { a[x]=1; if(!f) { f=1; printf("%d ",x); } xx=x; p--; } x++; } if(!f) printf("Can not put any one.\n"); else printf("%d\n",xx); }else { int s=0; for(int i=x; i<=y; i++) { s+=a[i]; a[i]=0; } printf("%d\n",s); } } } //原創200祭