답안 #845556

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
845556 2023-09-06T14:07:24 Z JMMirko XORanges (eJOI19_xoranges) C++14
0 / 100
140 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;
}

int 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() {
	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:76:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |     for(int i=2;i<x.size();i++){
      |                 ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 69 ms 2484 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 140 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -