CodeVS3147 矩阵乘法2

居然继续沦落到写CV的题解的地步了。 这又是一道坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑题。 思路很简单。就是记a的列前缀和和b的行前缀和,每次询问的时候O(n)的扫一遍乘积累和。 但是,极限数据本地要跑3.2s。虽然我笔记本是慢,但是也不能这样玩我啊。交了好久都在tle。 最后想到一个常数优化的办法。因为每次是把一行或者一列的数都访问一遍,所以用一个指针把数组的那一行记下来。这样寻址会快一些。事实证明快了不只一些。 坑,哈哈。 #include <cstdio> #include <cctype> #include <memory.h> #include <algorithm> using namespace std; typedef long long qw; #ifdef WIN32 #define lld "%I64d" #else #define lld "%lld" #endif #define _l (qw) #define readInt(_s_) {\ int _d_;\ _s_ = 0;\ while (!isdigit(_d_ = getchar()));\ while ((_s_ = _s_ * 10 + _d_ - 48), isdigit(_d_ = getchar()));\ } const int maxn = 2001; int a[maxn][maxn], b[maxn][maxn], n, m; int main() { readInt(n);...

October 18, 2014 · 1 min · laekov