Submission #1044755

# Submission time Handle Problem Language Result Execution time Memory
1044755 2024-08-05T13:15:49 Z vjudge1 Street Lamps (APIO19_street_lamps) C++17
0 / 100
349 ms 28552 KB
#include <bits/stdc++.h>
using std::cin, std::cout, std::vector, std::set, std::endl, std::string, std::map,std::pair,std::queue, std::max, std::min;

#ifdef LOCAL
#define file freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#else
#define file ;;
#endif

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

template <typename T>
using Tree = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#include <random>

class segt{
private:
	int n;
	vector<int> tree;
	int build(int node, int l, int r, vector<int>& a){
		if(l==r){
			return tree[node] = a[l-1];
		}
		int mid = (l+r)/2;
		return tree[node]=max(build(node*2, l, mid, a), build(node*2+1, mid+1, r, a));
	}

	void build(int n, vector<int> a){
		build(1, 1, n, a);
	}

	int update(int node, int l, int r, int x, int b){
		if(l==r){
			return tree[node]=b;
		}
		int mid = (l+r)/2;
		if(mid>=x) update(node*2,l,mid,x, b);
		else update(node*2+1,mid+1,r,x, b);
		return tree[node] = max(tree[node*2],tree[node*2+1]);
	}

	int query(int node, int l, int r, int x, int y){
		if(l>=x && r<=y){
			return tree[node];
		}
		int mid = (l+r)/2;
		if(mid<x) return query(node*2+1, mid+1, r, x, y);
		else if(mid>=y) return query(node*2, l, mid, x, y);
		return max(query(node*2,l,mid,x,y),query(node*2+1,mid+1,r,x,y));
	}

public:
	segt(vector<int> a){
		n = a.size();
		tree.resize(4*n+5);
		build(n,a);
	}

	void update(int x, int b){
		update(1,1,n,x,b);
	}

	int query(int l, int r){
		return query(1,1,n,l,r);
	}
};

int main(){
	file;
	int n,q;
	cin >> n >> q;
	string s;
	cin >> s;
	vector<int>a(n);
	for(int i=0;i<n;i++) a[i]=(s[i] == '1' ? 0:q+5);
	segt ss(a);
	vector<vector<int>> hist(n+1,vector<int>(1,0));
	for(int i=1;i<=q;i++){
		string ty;
		cin >> ty;
		if(ty[0]=='q'){
			int a,b;
			cin >> a >> b;
			cout << max(0,i-ss.query(a,b)) << endl;
		}
		else if(ty[0]=='t'){
			int a;
			cin >> a;
			ss.update(a,i);
		}

	}
	return 0;
}

# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 230 ms 2896 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 134 ms 27164 KB Output is correct
6 Correct 236 ms 27848 KB Output is correct
7 Incorrect 349 ms 28552 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -