社区讨论
关于memset
学术版参与者 9已保存回复 11
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 11 条
- 当前快照
- 1 份
- 快照标识符
- @mhizswc8
- 此快照首次捕获于
- 2025/11/03 18:23 4 个月前
- 此快照最后确认于
- 2025/11/03 20:26 4 个月前
在 这题中 我使用了memset 获得了TLE的高分
CPP//Source Code
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <cctype>
#include <set>
#include <stack>
//using namespace std;
using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned;
constexpr i64 N = 1e4 + 50;
constexpr i64 INF = 1e9 + 10;
constexpr i64 MOD = 998244353;
constexpr i64 P = 1e9 + 7;
i64 ans;
int _;
int n;
std :: string o;
int c[N][N] , a[N][N];
inline int lowbit (int x) {
return x & (-x);
}
inline void update (int x , int y , int val) {
for (int i = x;i <= n;i += lowbit (i))
for (int j = y;j <= n;j += lowbit (j))
c[i][j] += val;
return ;
}
inline int query (int x , int y) {
int res = 0;
for (int i = x;i >= 1;i -= lowbit (i))
for (int j = y;j >= 1;j -= lowbit (j))
res += c[i][j];
return res;
}
inline void solve(){
std :: cin >> n;
std :: memset (c , 0 , sizeof (c));
std :: memset (a , 0 , sizeof (a));
while (1) {
std :: cin >> o;
// std :: cout << o << '\n';
// std :: cout << "---------------------------------------" << '\n';
int x , y , X , Y , val;
if (o == "END") return ;
if (o == "SET") {
std :: cin >> x >> y;
x ++ , y ++;
std :: cin >> val;
update (x , y , val - a[x][y]);
a[x][y] = val;
} if (o == "SUM") {
std :: cin >> x >> y >> X >> Y;
x ++ , y ++ , X ++ , Y ++;
std :: cout << query (X , Y) - query (x - 1 , Y) - query (X , y - 1) + query (x - 1 , y - 1) << '\n';
}
}
return ;
}
signed main(){
std :: ios :: sync_with_stdio(false);
std :: cin.tie(0) , std :: cout.tie(0);
std :: cin >> _;
//_ = 1;
while(_ --> 0) solve();
return (0 - 0);
}
/*
1
4
SET 0 0 1
SUM 0 0 3 3
SET 2 2 12
SUM 2 2 2 2
SUM 2 2 3 3
SUM 0 0 2 2
END
*/
然而,我将memset改成for循环,却AC了
CPP//Source Code
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <cctype>
#include <set>
#include <stack>
//using namespace std;
using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned;
constexpr i64 N = 3e4;
constexpr i64 INF = 1e9 + 10;
constexpr i64 MOD = 998244353;
constexpr i64 P = 1e9 + 7;
i64 ans;
int _;
int n , m;
std :: string fuckfuckfuck;
std :: string o;
int a[N][N] , c[N][N];
inline int lowbit (int x) {
return x & (-x);
}
inline void update (int x , int y , int val) {
for (int i = x;i <= n;i += lowbit (i))
for (int j = y;j <= n;j += lowbit (j))
c[i][j] += val;
return ;
}
inline int query (int x , int y) {
int res = 0;
for (int i = x;i >= 1;i -= lowbit (i))
for (int j = y;j >= 1;j -= lowbit (j))
res += c[i][j];
return res;
}
inline void solve(){
std :: cin >> fuckfuckfuck >> n >> m;
while (std :: cin >> o) {
int x , y , X , Y;
if (o == "k") {
std :: cin >> x >> y >> X >> Y;
x ++ , y ++ , X ++ , Y ++;
std :: cout << query (X , Y) - query (x - 1 , Y) - query (X , y - 1) + query (x - 1 , y - 1) << '\n';
}
}
return ;
}
signed main(){
std :: ios :: sync_with_stdio(false);
std :: cin.tie(0) , std :: cout.tie(0);
//std :: cin >> _;
_ = 1;
while(_ --> 0) solve();
return (0 - 0);
}
/*
//Source Code
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <cctype>
#include <set>
#include <stack>
//using namespace std;
using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned;
constexpr i64 N = 1e4 + 50;
constexpr i64 INF = 1e9 + 10;
constexpr i64 MOD = 998244353;
constexpr i64 P = 1e9 + 7;
i64 ans;
int _;
int n;
std :: string o;
int c[N][N] , a[N][N];
inline int lowbit (int x) {
return x & (-x);
}
inline void update (int x , int y , int val) {
for (int i = x;i <= n;i += lowbit (i))
for (int j = y;j <= n;j += lowbit (j))
c[i][j] += val;
return ;
}
inline int query (int x , int y) {
int res = 0;
for (int i = x;i >= 1;i -= lowbit (i))
for (int j = y;j >= 1;j -= lowbit (j))
res += c[i][j];
return res;
}
inline void solve(){
std :: cin >> n;
for (int i = 1;i <= n;i ++)
for (int j = 1;j <= n;j ++)
a[i][j] = 0 , c[i][j] = 0;
while (1) {
std :: cin >> o;
// std :: cout << o << '\n';
// std :: cout << "---------------------------------------" << '\n';
int x , y , X , Y , val;
if (o == "END") {
break;
}
if (o == "SET") {
std :: cin >> x >> y;
x ++ , y ++;
std :: cin >> val;
update (x , y , val - a[x][y]);
a[x][y] = val;
} if (o == "SUM") {
std :: cin >> x >> y >> X >> Y;
x ++ , y ++ , X ++ , Y ++;
std :: cout << query (X , Y) - query (x - 1 , Y) - query (X , y - 1) + query (x - 1 , y - 1) << '\n';
}
}
return ;
}
signed main(){
std :: ios :: sync_with_stdio(false);
std :: cin.tie(0) , std :: cout.tie(0);
std :: cin >> _;
//_ = 1;
while(_ --> 0) solve();
return (0 - 0);
}
/*
1
4
SET 0 0 1
SUM 0 0 3 3
SET 2 2 12
SUM 2 2 2 2
SUM 2 2 3 3
SUM 0 0 2 2
END
*/
回复
共 11 条回复,欢迎继续交流。
正在加载回复...