求一组hack数据
查看原帖
求一组hack数据
155767
Tarsal楼主2020/10/24 21:13

RT

我的代码

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ls (x << 1)
#define rs (x << 1 | 1)
#define mid ((l + r) >> 1)
const int maxn = 2e5 + 10;
int n, m, opt, l, r, v, a[maxn];
struct node {
	int lazy;
	double Sin, Cos;
} e[maxn << 2];
void pushup(int x) {
	e[x].Sin = e[ls].Sin + e[rs].Sin;
	e[x].Cos = e[rs].Cos + e[rs].Cos;
//	e[x].Sin = e[ls].Sin * e[rs].Cos + e[ls].Cos * e[rs].Sin;
//	e[x].Cos = e[ls].Cos * e[rs].Cos - e[ls].Sin * e[rs].Sin;
}
void pushdown(int x, int l, int r) {
	if(e[x].lazy == 0) {
		return ;
	}
	e[ls].lazy += e[x].lazy;
	e[rs].lazy += e[x].lazy;
	double SSS = e[rs].Sin, CCC = e[rs].Cos;
	e[rs].Sin = SSS * cos(e[x].lazy) + sin(e[x].lazy) * CCC;
	e[rs].Cos = cos(e[x].lazy) * CCC - SSS * sin(e[x].lazy);
	SSS = e[ls].Sin, CCC = e[ls].Cos;
	e[ls].Sin = SSS * cos(e[x].lazy) + sin(e[x].lazy) * CCC;
	e[ls].Cos = cos(e[x].lazy) * CCC - SSS * sin(e[x].lazy);
	e[x].lazy = 0;
}
void Build(int x, int l, int r) {
	if(l == r) {
		e[x].Sin = sin(a[l]);
		e[x].Cos = cos(a[l]);
//		printf("lll %lf %lf\n", e[x].Sin, e[x].Cos);
		return ;
	}
	Build(ls, l, mid), Build(rs, mid + 1, r);
	pushup(x);
}
void Modify(int x, int l, int r, int L, int R, int k) {
	if(l >= L && r <= R) {
		e[x].lazy += k;
		double SSS = e[x].Sin, CCC = e[x].Cos;
		e[x].Sin = SSS * cos(k) + sin(k) * CCC;
		e[x].Cos = cos(k) * CCC - SSS * sin(k);
		return ;
	}
	pushdown(x, l, r);
	if(mid >= L) {
		Modify(ls, l, mid, L, R, k);
	}
	if(mid < R) {
		Modify(rs, mid + 1, r, L, R, k);
	}
	pushup(x);
}
double Query(int x, int l, int r, int L, int R) {
	if(l >= L && r <= R) {
		return e[x].Sin;
	}
	pushdown(x, l, r);
	double ans = 0;
	if(mid >= L) {
		ans += Query(ls, l, mid, L, R);
	}
	if(mid < R) {
		ans += Query(rs, mid + 1, r, L, R);
	}
	return ans;
}
signed main() {
    freopen("a.in", "r", stdin);
    freopen("a.out", "w", stdout);
	scanf("%lld", &n);
	for(int i = 1; i <= n; ++ i) {
		scanf("%lld", &a[i]);
	}
	Build(1, 1, n);
	scanf("%lld", &m);
	while(m --) {
		scanf("%lld%lld%lld", &opt, &l, &r);
		if(opt == 1) {
			scanf("%lld", &v);
			Modify(1, 1, n, l, r, v);
		}
		else {
			printf("%.1lf\n", Query(1, 1, n, l, r));
		}
	}
	return 0;
}

maker

#include <bits/stdc++.h>
using namespace std;
int main() {
    freopen("a.in", "w", stdout);
    srand(time(0));
    int n = rand() % 100000 + 100000;
    printf("%d\n", n);
    for(int i = 1; i <= n; ++ i) {
        printf("%d ", rand() % 100000 + 1);
    }
    puts("");
    int m = rand() % 100000 + 100000;
    for(int i = 1; i <= m; ++ i) {
        int opt = rand() % 2 + 1, l = rand() % 100000 + 1;
        if(opt == 1) {
            printf("%d %d %d %d\n", opt, l, rand() % 100000 + l + 10, rand() % 100000 - 1000);
        }
        else {
            printf("%d %d %d\n", opt, l, rand() % 100000 + l + 10);
        }
    }
    return 0;
}

@echo off
:loop
Make.exe
P6327.exe
test.exe
fc a.out test.out
if not errorlevel 1 goto loop
pause
:end

test是一个暴力修改和查询的暴力,也可以找题解对拍。

拍了10分钟了,还是找不到差异,但是就是全wa

2020/10/24 21:13
加载中...