結果
| 問題 |
No.1589 Bit Vector
|
| コンテスト | |
| ユーザー |
Nachia
|
| 提出日時 | 2021-07-09 01:11:40 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 7 ms / 2,000 ms |
| コード長 | 3,870 bytes |
| コンパイル時間 | 5,833 ms |
| コンパイル使用メモリ | 229,956 KB |
| 最終ジャッジ日時 | 2025-01-22 19:57:12 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 35 |
ソースコード
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
template<class S, class T> inline S min_L(S a,T b){
return a<=b?a:b;
}
inline int my_getchar(){
static char buf[1048576];
static int s = 1048576;
static int e = 1048576;
if(s == e && e == 1048576){
e = fread(buf, 1, 1048576, stdin);
s = 0;
}
if(s == e){
return EOF;
}
return buf[s++];
}
inline void rd(int &x){
int k;
int m=0;
x=0;
for(;;){
k = my_getchar();
if(k=='-'){
m=1;
break;
}
if('0'<=k&&k<='9'){
x=k-'0';
break;
}
}
for(;;){
k = my_getchar();
if(k<'0'||k>'9'){
break;
}
x=x*10+k-'0';
}
if(m){
x=-x;
}
}
struct MY_WRITER{
char buf[1048576];
int s;
int e;
MY_WRITER(){
s = 0;
e = 1048576;
}
~MY_WRITER(){
if(s){
fwrite(buf, 1, s, stdout);
}
}
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar(int a){
if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
fwrite(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
MY_WRITER_VAR.s = 0;
}
MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
my_putchar(a);
}
inline void wt_L(int x){
int s=0;
int m=0;
char f[10];
if(x<0){
m=1;
x=-x;
}
while(x){
f[s++]=x%10;
x/=10;
}
if(!s){
f[s++]=0;
}
if(m){
my_putchar('-');
}
while(s--){
my_putchar(f[s]+'0');
}
}
inline void wt_L(const char c[]){
int i=0;
for(i=0;c[i]!='\0';i++){
my_putchar(c[i]);
}
}
int N;
int K;
int anscnt = 0;
void push_upd(int i,int x){
anscnt++;
wt_L("UPD");
wt_L(' ');
wt_L(i);
wt_L(' ');
wt_L(x);
wt_L('\n');
}
void push_and(int i,int x,int y){
anscnt++;
wt_L("AND");
wt_L(' ');
wt_L(i);
wt_L(' ');
wt_L(x);
wt_L(' ');
wt_L(y);
wt_L('\n');
}
void push_xor(int i,int x,int y){
anscnt++;
wt_L("XOR");
wt_L(' ');
wt_L(i);
wt_L(' ');
wt_L(x);
wt_L(' ');
wt_L(y);
wt_L('\n');
}
void add1(int l1,int r1,int b){
int n = N;
for(int i=l1; i<r1; i++){
push_and(n,i,b);
push_xor(i,i,b);
swap(n,b);
}
push_and(r1,b,b);
}
void comp(int l1,int r1,int k,int p){
if(k & 1){
push_and(p,l1,l1);
}
else{
push_upd(p,1);
}
for(int i=l1+1; i<r1; i++){
k >>= 1;
if(k & 1){
push_and(p,i,p);
}
else{
push_upd(i-1,1);
push_xor(p,i-1,p);
push_xor(i,i-1,i);
push_and(p,i,p);
push_xor(p,i-1,p);
}
}
}
void solve(int n,int k){
anscnt = 0;
for(int i=1; i<n; i++){
add1(0,min_L(i, 6),i);
}
comp(0,min_L(n, 6),k,n);
}
int main(){
wt_L(633);
wt_L('\n');
rd(N);
rd(K);
solve(N,K);
if(anscnt > 633){
exit(1);
}
for(; anscnt<633; anscnt++){
wt_L("UPD 0 0");
wt_L('\n');
}
return 0;
}
// cLay varsion 20201003-1
// --- original code ---
//
// int N,K;
// int anscnt = 0;
//
// void push_upd(int i,int x){ anscnt++; wt("UPD",i,x); }
// void push_and(int i,int x,int y){ anscnt++; wt("AND",i,x,y); }
// void push_xor(int i,int x,int y){ anscnt++; wt("XOR",i,x,y); }
//
// void add1(int l1,int r1,int b){
// int n = N;
// for(int i=l1; i<r1; i++){
// push_and(n,i,b);
// push_xor(i,i,b);
// swap(n,b);
// }
// push_and(r1,b,b);
// }
//
// void comp(int l1,int r1,int k,int p){
// if(k & 1) push_and(p,l1,l1);
// else push_upd(p,1);
// for(int i=l1+1; i<r1; i++){
// k >>= 1;
// if(k & 1) push_and(p,i,p);
// else{
// push_upd(i-1,1);
// push_xor(p,i-1,p);
// push_xor(i,i-1,i);
// push_and(p,i,p);
// push_xor(p,i-1,p);
// }
// }
// }
//
// void solve(int n,int k){
// anscnt = 0;
// for(int i=1; i<n; i++) add1(0,min(i,6),i);
// comp(0,min(n,6),k,n);
// }
//
// {
// wt(633);
// rd(N,K);
// solve(N,K);
// if(anscnt > 633) exit(1);
// for(; anscnt<633; anscnt++) wt("UPD 0 0");
// return 0;
// }
Nachia