1784:camellia's Puzzle time limit: 2 Sec Memory Limit: 14 MB Submit: Solved
Submitstatusweb Board Description
Camellia encountered a problem, she could not solve the beans, the following is the question that beans understand: given 10 million points, number 110 million. Each point has a value, the initial time is 1, there are N operations, the operation of the following five.
1 x represents the update of the X point to I,i for the first few operations.
2 x indicates that the x point is updated to-1.
3 represents turning all points into-1.
4 x queries the value of the X point.
5 query 10 million points in the number of points is not-1.
Dear classmates, can you help them solve this problem?
Input
First enter a T (t<10) for the T array, then each group of data first enter an n (n<100 million) for n operations, the next n rows of one operation per row.
Output
For 4, 5 operations to speak, output their answers.
Sample Input1 8 1 1 4, 5 2, 5 3 5Sample Output1 2 1 0The problem: This is to give a series of operations, of which 4 and 5 are inquired ... violence, used to use memset, how to use, who know this time hanging, the original memset is very slow, the running time is sizeof (DT); This time is n*sizeof (DT) So it will time out, so, think of an array to save is not-1 of the number, When operating 3, you just need to change the number not-1 to 1. It's really superfluous to start with a tree-like array, and that's even slower ... Code:
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <algorithm>6 using namespacestd;7 #defineMem (x, y) memset (x,y,sizeof (x))8typedefLong LongLL;9 Const intmaxn=1e7+Ten;Ten intDT[MAXN],V[MAXN]; One /*int lowbit (int x) {return x& (-X);} A void Update (int x,int y) { - While (X<MAXN) { - tree[x]+=y; the x+=lowbit (x); - } - } - int Q (int x) { + int sum=0; - While (x>0) { + Sum+=tree[x]; A x-=lowbit (x); at } - return sum; - }*/ - intMain () { - intT,n; -scanf"%d",&t); in while(t--){ -scanf"%d",&n); toMEM (dt,-1); + intflot=0, ans=0; - intGg,x,cc=0; the while(n--){ *flot++; $scanf"%d",&GG);Panax Notoginseng if(gg==1){ -scanf"%d",&x); the if(dt[x]==-1) ans++; +dt[x]=Flot; Av[cc++]=x; the Continue; + } - if(gg==2){ $scanf"%d",&x); $ if(dt[x]!=-1) ans--; -dt[x]=-1; - Continue; the } - if(gg==3){Wuyi for(intkk=0; kk<cc;kk++) dt[v[kk]]=-1; theCc=0; -ans=0; Wu Continue; - } About if(gg==4){ $scanf"%d",&x); -printf"%d\n", dt[x]); - Continue; - } A if(gg==5){ +printf"%d\n", ans); the Continue; - } $ } the } the return 0; the}
Zzuli Camellia's problem (violence)