Submission #124573

# Submission time Handle Problem Language Result Execution time Memory
124573 2019-07-03T14:12:39 Z TadijaSebez Street Lamps (APIO19_street_lamps) C++11
0 / 100
1246 ms 4952 KB
#include <bits/stdc++.h>
using namespace std;
const int N=300050;
const int M=18*18*N;
int state[N];
struct Seg
{
	int l,r,tme;
	Seg(){}
	Seg(int a, int b, int c):l(a),r(b),tme(c){}
	bool operator < (Seg b) const { return l<b.l;}
};
set<Seg> all;
Seg Get(int x)
{
	auto it=all.lower_bound(Seg(x+1,0,0));
	it--;
	return *it;
}
int root[N],ls[M],rs[M],tsz,sum[M];
void Set(int &c, int ss, int se, int qs, int qe, int x)
{
	if(qs>qe || qs>se || ss>qe) return;
	if(!c) c=++tsz;
	if(qs<=ss && qe>=se){ sum[c]+=x;return;}
	int mid=ss+se>>1;
	Set(ls[c],ss,mid,qs,qe,x);
	Set(rs[c],mid+1,se,qs,qe,x);
}
int Get(int c, int ss, int se, int qi)
{
	if(ss==se) return sum[c];
	int mid=ss+se>>1;
	if(qi<=mid) return sum[c]+Get(ls[c],ss,mid,qi);
	else return sum[c]+Get(rs[c],mid+1,se,qi);
}
void Set(int qi, int l, int r, int x)
{
	for(int i=qi;i<N;i+=i&-i) Set(root[i],1,N,l,r,x);
}
void Set(int l, int r, int x)
{
	Set(l,l,r,x);
	Set(r+1,l,r,-x);
}
int Get(int x, int y)
{
	int ans=0;
	for(int i=x;i;i-=i&-i) ans+=Get(root[i],1,N,y);
	return ans;
}
void Set(Seg sg, int tme)
{
	Set(sg.l,sg.r,sg.tme-tme);
}
void Update(int x, int tme)
{
	if(state[x])
	{
		Seg tmp=Get(x);
		Set(tmp,tme);
		all.erase(tmp);
		all.insert(Seg(tmp.l,x,tme));
		all.insert(Seg(x+1,tmp.r,tme));
	}
	else
	{
		Seg L=Get(x),R=Get(x+1);
		Set(L,tme);
		Set(R,tme);
		all.erase(L);
		all.erase(R);
		all.insert(Seg(L.l,R.r,tme));
	}
	state[x]^=1;
}
char s[N];
int main()
{
	int n,q;
	scanf("%i %i",&n,&q);
	scanf("%s",s+1);
	for(int i=1;i<=n;i++) state[i]=s[i]=='1';
	for(int i=1,j=1;i<=n+1;i=j+1)
	{
		for(j=i;j<=n && state[j];j++);
		all.insert(Seg(i,j,0));
	}
	char t[10];
	for(int i=1;i<=q;i++)
	{
		scanf("%s",t);
		if(t[0]=='t')
		{
			int x;
			scanf("%i",&x);
			Update(x,i);
		}
		else
		{
			int a,b;
			scanf("%i %i",&a,&b);
			int ans=Get(a,b);
			Seg tmp=Get(a);
			if(tmp.r>=b) ans+=i-tmp.tme;
			printf("%i\n",ans);
		}
	}
	return 0;
}

Compilation message

street_lamps.cpp: In function 'void Set(int&, int, int, int, int, int)':
street_lamps.cpp:26:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid=ss+se>>1;
          ~~^~~
street_lamps.cpp: In function 'int Get(int, int, int, int)':
street_lamps.cpp:33:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid=ss+se>>1;
          ~~^~~
street_lamps.cpp: In function 'int main()':
street_lamps.cpp:81:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i %i",&n,&q);
  ~~~~~^~~~~~~~~~~~~~~
street_lamps.cpp:82:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s",s+1);
  ~~~~~^~~~~~~~~~
street_lamps.cpp:92:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s",t);
   ~~~~~^~~~~~~~
street_lamps.cpp:96:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%i",&x);
    ~~~~~^~~~~~~~~
street_lamps.cpp:102:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%i %i",&a,&b);
    ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1246 ms 4952 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 1144 KB Output is correct
2 Incorrect 10 ms 1016 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Incorrect 5 ms 772 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -