Submission #845875

# Submission time Handle Problem Language Result Execution time Memory
845875 2023-09-06T17:11:13 Z JMMirko XORanges (eJOI19_xoranges) C++17
0 / 100
98 ms 65536 KB
// Source: https://usaco.guide/general/io

#include <bits/stdc++.h>
using namespace std;
string bin(int x){
	string s;
	while(x!=0){
		if(x%2==1)s.push_back('1');
		else s.push_back('0');
		x/=2;
	}
	while(s.size()!=30){
		s.push_back('0');
	}
	reverse(s.begin(),s.end());
	return s;
}

string xr(string a, string b){
	string s;
	for(int i=0;i<30;i++){
		if(a[i]==b[i])s.push_back('0');
		else s.push_back('1');
	}
	return s;
}

long long nib(string s){
	long long r=0,m;
	reverse(s.begin(),s.end());
	m=1;
	for(int i=0;i<30;i++){
		r+=(s[i]-'0')*m;
		m*=2;
	}
	return r;
}


int main() {
	std::ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n,q;
	cin >> n >> q;
	vector<string> s(n);
	for(int i=0;i<n;i++){
		int a;
		cin >> a;
		s[i]=bin(a);
	}
	vector<vector<int> > v(n+1,vector<int>(n+1));
	for(int i=1;i<n+1;i++){
		for(int j=1;j<i+1;j++){
			for(int k=1;k<i+1;k++){
				v[i][j]+=min(j,min(i-j+1,min(i-k+1,k)));
				v[i][j]=v[i][j]%2;
			}
		}
	}
	for(int z=0;z<q;z++){
		vector<int> x;
		int a;
		cin >> a;
		if(a==1){
			int b;
			cin >> a >> b;
			s[a-1]=bin(b);
		}else{
			int b;
			cin >> a >> b;
			for(int i=1;i<=b-a+1;i++){
				if(v[b-a+1][i]%2==1)x.push_back(a+i-2);
			}
			string e;
			if (x.size()>1){
				string aaa=s[x[0]],bbb=s[x[1]];
				e=xr(aaa,bbb);
				for(int i=2;i<x.size();i++){
					e=xr(e,s[x[i]]);
				}
			}else e=s[x[0]];
			cout << nib(e) << endl;
		}
	}
}

Compilation message

xoranges.cpp: In function 'int main()':
xoranges.cpp:78:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |     for(int i=2;i<x.size();i++){
      |                 ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 69 ms 2512 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 98 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -