评测机好像越来越卡了

我刚刚递交了2次测试,代码是一样的……结果一次TLE一次AC!天理难容啊……
话说回来,毕竟我的代码是O(N)的时间复杂度,结果200,000+的数据跑了900ms……是不是我的输入模式不对(iostream是不是比cstdio慢呢?)
下面是代码……

#include<iostream>
using namespace std;

long n, k, p,pay,color,ans;
long f[200009], munc[8000], point[8000], mark[200009] = { 0 };

int main()
{
cin >> n>>k>>p;
ans = 0;
for (long i = 1; i <= n; i++)
{
cin >> color>>pay;
if (pay <= p) f[i] = f[i - 1] + 1;
else f[i] = f[i - 1];
if (munc[color] != 0)
ans +=mark[i]=(f[i] - f[point[color]-1] > 0 ? munc[color] : mark[point[color]]);
point[color] = i;
munc[color]++;
}
cout << ans;
system("pause");
return 0;
}

还有别问我那个system("pause")是什么,我用Visual Studio写的,调试的时候用的东西,递交的时候注释掉

3 条评论

  • @ 2015-10-03 23:00:58

    c++的标准输入流很慢,所以有时候要采用读入优化

  • @ 2015-09-26 16:17:21

    c++选手请谨慎使用iostream

  • @ 2015-09-26 16:01:46

    那个system("pause")是什么

  • 1

信息

ID
1737
难度
6
分类
数据结构 | 单调队列 点击显示
标签
递交数
3860
已通过
1162
通过率
30%
被复制
8
上传者