//
// main.cpp
// P3987 我永远喜欢珂朵莉~
//
// Created by SkyWave Sun on 2023/5/1.
//
#include <iostream>
using namespace std;
#define N (int)1e5 + 1
#define lowbit(x) (x & -x)
int read() {
char c = getchar();
int num = 0;
while (c < '0' || c > '9') {
c = getchar();
}
while (c >= '0' && c <= '9') {
num = (num << 1) + (num << 3) + (c ^ 48);
c = getchar();
}
return num;
}
int main(int argc, const char * argv[]) {
int a[N];
int n = read(), m = read();
int i;
for (i = 1; i <= n - 4; i += 4) {
a[i] = read(); a[i + 1] = read(); a[i + 2] = read(); a[i + 3] = read();
}
for ( ; i <= n; ++i) {
a[i] = read();
}
while (m--) {
bool method = read() & 1;
int l = read(), r = read();
if (method) {
int x = read();
if (x == 2) {
for (i = l; i <= r - 4; i += 4) {
if (!(a[i] & 1)) {
a[i] >>= 1;
}
if (!(a[i + 1] & 1)) {
a[i + 1] >>= 1;
}
if (!(a[i + 2] & 1)) {
a[i + 2] >>= 1;
}
if (!(a[i + 3] & 1)) {
a[i + 3] >>= 1;
}
}
for (; i <= r; ++i) {
if (!(a[i] & 1)) {
a[i] >>= 1;
}
}
}else if (x == lowbit(x)) {
int tmp = __builtin_ctz(x);
for (i = l; i <= r - 4; i += 4) {
if (a[i] % x == 0) {
a[i] >>= tmp;
}
if (a[i + 1] % x == 0) {
a[i + 1] >>= tmp;
}
if (a[i + 2] % x == 0) {
a[i + 2] >>= tmp;
}
if (a[i + 3] % x == 0) {
a[i + 3] >>= tmp;
}
}
for ( ; i <= r; ++i) {
if (a[i] % x == 0) {
a[i] >>= tmp;
}
}
}else if (x > 2) {
for (i = l; i <= r - 4; i += 4) {
if (a[i] % x == 0) {
a[i] /= x;
}
if (a[i + 1] % x == 0) {
a[i + 1] /= x;
}
if (a[i + 2] % x == 0) {
a[i + 2] /= x;
}
if (a[i + 3] % x == 0) {
a[i + 3] /= x;
}
}
for ( ; i <= r; ++i) {
if (a[i] % x == 0) {
a[i] /= x;
}
}
}
}else {
long long sum = 0;
for (int i = l; i <= r; ++i) {
sum += a[i];
}
printf("%llu\n",sum);
}
}
return 0;
}
这一串代码能得 91 分
但注释掉对于 2n 时,除法变成位移,反而可以得 94 分,评测多次,确认不是评测机波动,是为什么呢
代码如下
//
// main.cpp
// P3987 我永远喜欢珂朵莉~
//
// Created by SkyWave Sun on 2023/5/1.
//
#include <iostream>
using namespace std;
#define N (int)1e5 + 1
#define lowbit(x) (x & -x)
int read() {
char c = getchar();
int num = 0;
while (c < '0' || c > '9') {
c = getchar();
}
while (c >= '0' && c <= '9') {
num = (num << 1) + (num << 3) + (c ^ 48);
c = getchar();
}
return num;
}
int main(int argc, const char * argv[]) {
int a[N];
int n = read(), m = read();
int i;
for (i = 1; i <= n - 4; i += 4) {
a[i] = read(); a[i + 1] = read(); a[i + 2] = read(); a[i + 3] = read();
}
for ( ; i <= n; ++i) {
a[i] = read();
}
while (m--) {
bool method = read() & 1;
int l = read(), r = read();
if (method) {
int x = read();
if (x == 2) {
for (i = l; i <= r - 4; i += 4) {
if (!(a[i] & 1)) {
a[i] >>= 1;
}
if (!(a[i + 1] & 1)) {
a[i + 1] >>= 1;
}
if (!(a[i + 2] & 1)) {
a[i + 2] >>= 1;
}
if (!(a[i + 3] & 1)) {
a[i + 3] >>= 1;
}
}
for (; i <= r; ++i) {
if (!(a[i] & 1)) {
a[i] >>= 1;
}
}
}/*else if (x == lowbit(x)) {
int tmp = __builtin_ctz(x);
for (i = l; i <= r - 4; i += 4) {
if (a[i] % x == 0) {
a[i] >>= tmp;
}
if (a[i + 1] % x == 0) {
a[i + 1] >>= tmp;
}
if (a[i + 2] % x == 0) {
a[i + 2] >>= tmp;
}
if (a[i + 3] % x == 0) {
a[i + 3] >>= tmp;
}
}
for ( ; i <= r; ++i) {
if (a[i] % x == 0) {
a[i] >>= tmp;
}
}
}*/else if (x > 2) {
for (i = l; i <= r - 4; i += 4) {
if (a[i] % x == 0) {
a[i] /= x;
}
if (a[i + 1] % x == 0) {
a[i + 1] /= x;
}
if (a[i + 2] % x == 0) {
a[i + 2] /= x;
}
if (a[i + 3] % x == 0) {
a[i + 3] /= x;
}
}
for ( ; i <= r; ++i) {
if (a[i] % x == 0) {
a[i] /= x;
}
}
}
}else {
long long sum = 0;
for (int i = l; i <= r; ++i) {
sum += a[i];
}
printf("%llu\n",sum);
}
}
return 0;
}