Submission #407273

# Submission time Handle Problem Language Result Execution time Memory
407273 2021-05-18T16:57:42 Z anime Street Lamps (APIO19_street_lamps) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <class T> using ordered_set = tree<T,null_type,less_equal<T>, rb_tree_tag,tree_order_statistics_node_update>;

/#define int long long
#define pb push_back
#define pii pair<int,int>
#define fr first
#define sc second
#define OK puts("OK");
#define NO puts("NO");
#define YES puts("YES");
#define endi puts("");
#define ret return
#define all(s) s.begin(),s.end()
#define allr(s) s.rbegin(),s.rend()
const int N = 3e5+5,INF = 1e9+7;
int q[N],z[N],xo;
char s[N];
vector <pair<pii,int>> der[4*N];

void update(int v,int l,int r,int ql,int qr,int lol,int ror,int cost){
	
	if (l > qr || r < ql)ret ;
	if (ql <= l && r <= qr){
		der[v].pb({{lol,ror},cost});
		ret ;
	}
	int m = l+r>>1;
	update(v<<1,l,m,ql,qr,lol,ror,cost);
	update(v<<1|1,m+1,r,ql,qr,lol,ror,cost);
}

int get_ans(int v,int l,int r,int pos,int x){
	
	int ans=0;
	for (pair<pii,int> z: der[v])
		if (z.fr.fr <= x && x <= z.fr.sc)
			ans += z.sc,xo^=1;
	
	if (l == r)ret ans;
	int m = l+r>>1;
	if (pos > m)
		ret get_ans(v<<1|1,m+1,r,pos,x)+ans;
	ret get_ans(v<<1,l,m,pos,x)+ans;
	
}




main(){
	int n,t,i;
	scanf("%d%d",&n,&t);
	scanf("%s",s+1);
	s[0] = s[n+1] = '0';
	set <int> as;
	for (i=0;i<=n+1;++i)
		if (s[i] == '0')as.insert(i);
	for (i=0;i<=n+1;++i){
		if(s[i] == '0') continue;
		int j=i;
		while(j <= n+1 && s[j] == s[i]) j++;
		update(1, 1, n, i, j-1, i, j-1, 0);
		i = j - 1;
	}
	for (i=1;i<=t;++i){
		char ss[7];
		scanf("%s",ss);
		if (ss[0] == 'q'){
			int l,r;
			scanf("%d%d",&l,&r);
			
			r--;
			xo = 0;
			int ans = get_ans(1,1,n,l,r);
			if (xo)ans += i;
			printf("%d\n",ans);
		}
		else {
			int pos;
			scanf("%d",&pos);
			if (s[pos] == '0'){
				as.erase(pos);
				int l = *--as.upper_bound(pos);
				int r = *as.lower_bound(pos);
				update(1,1,n,l+1,pos,pos,r-1,-i);
				s[pos] = '1';
			} 
			else {
				int l = *--as.upper_bound(pos);
				int r = *as.lower_bound(pos);
				update(1,1,n,l+1,pos,pos,r-1,i);
				s[pos] = '0';
				as.insert(pos);
				
			}
			
		}
	}
	
	
}
 
 
 
 
 
 
 
 
 
 
 
 

Compilation message

street_lamps.cpp:9:2: error: stray '#' in program
    9 | /#define int long long
      |  ^
street_lamps.cpp:9:1: error: expected unqualified-id before '/' token
    9 | /#define int long long
      | ^
street_lamps.cpp:22:7: error: 'N' was not declared in this scope; did you mean 'NO'?
   22 | int q[N],z[N],xo;
      |       ^
      |       NO
street_lamps.cpp:22:12: error: 'N' was not declared in this scope; did you mean 'NO'?
   22 | int q[N],z[N],xo;
      |            ^
      |            NO
street_lamps.cpp:23:8: error: 'N' was not declared in this scope; did you mean 'NO'?
   23 | char s[N];
      |        ^
      |        NO
street_lamps.cpp:24:30: error: 'N' was not declared in this scope; did you mean 'NO'?
   24 | vector <pair<pii,int>> der[4*N];
      |                              ^
      |                              NO
street_lamps.cpp: In function 'void update(int, int, int, int, int, int, int, int)':
street_lamps.cpp:30:3: error: 'der' was not declared in this scope
   30 |   der[v].pb({{lol,ror},cost});
      |   ^~~
street_lamps.cpp:33:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   33 |  int m = l+r>>1;
      |          ~^~
street_lamps.cpp: In function 'int get_ans(int, int, int, int, int)':
street_lamps.cpp:41:24: error: 'der' was not declared in this scope
   41 |  for (pair<pii,int> z: der[v])
      |                        ^~~
street_lamps.cpp:46:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   46 |  int m = l+r>>1;
      |          ~^~
street_lamps.cpp: At global scope:
street_lamps.cpp:56:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   56 | main(){
      | ^~~~
street_lamps.cpp: In function 'int main()':
street_lamps.cpp:59:13: error: 's' was not declared in this scope
   59 |  scanf("%s",s+1);
      |             ^
street_lamps.cpp:58:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |  scanf("%d%d",&n,&t);
      |  ~~~~~^~~~~~~~~~~~~~
street_lamps.cpp:73:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |   scanf("%s",ss);
      |   ~~~~~^~~~~~~~~
street_lamps.cpp:76:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |    scanf("%d%d",&l,&r);
      |    ~~~~~^~~~~~~~~~~~~~
street_lamps.cpp:86:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   86 |    scanf("%d",&pos);
      |    ~~~~~^~~~~~~~~~~