Codeforces Round #582 (Div. 3) --B. Bad Prices--打表找规律

B. Bad Prices

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Polycarp analyzes the prices of the new berPhone. At his disposal are the prices for nn last days: a1,a2,…,ana1,a2,…,an, where aiai is the price of berPhone on the day ii.

Polycarp considers the price on the day ii to be bad if later (that is, a day with a greater number) berPhone was sold at a lower price. For example, if n=6n=6 and a=[3,9,4,6,7,5]a=[3,9,4,6,7,5], then the number of days with a bad price is 33 — these are days 22 (a2=9a2=9), 44 (a4=6a4=6) and 55(a5=7a5=7).

Print the number of days with a bad price.

You have to answer tt independent data sets.

Input

The first line contains an integer tt (1≤t≤100001≤t≤10000) — the number of sets of input data in the test. Input data sets must be processed independently, one after another.

Each input data set consists of two lines. The first line contains an integer nn (1≤n≤1500001≤n≤150000) — the number of days. The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1061≤ai≤106), where aiai is the price on the ii-th day.

It is guaranteed that the sum of nn over all data sets in the test does not exceed 150000150000.

Output

Print tt integers, the jj-th of which should be equal to the number of days with a bad price in the jj-th input data set.

Example

input

Copy

5
6
3 9 4 6 7 5
1
1000000
2
2 1
10
31 41 59 26 53 58 97 93 23 84
7
3 2 1 2 3 4 5

output

Copy

3
0
1
8
2

问1-n中有多少个i可以被m整除,输出他们最末位之和。

先统计出ans[i]=ans[i-1]+i*m%10 代表前缀和。然后t=n/m,看t是多少,然后t*ans[10]+ans[t%10]。

#include <algorithm>    //STL通用算法
#include <bitset>     //STL位集容器
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>     //复数类
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>      //STL双端队列容器
#include <exception>    //异常处理类
#include <fstream>
#include <functional>   //STL定义运算函数(代替运算符)
#include <limits>
#include <list>      //STL线性列表容器
#include <map>       //STL 映射容器
#include <iomanip>
#include <ios>      //基本输入/输出支持
#include<iosfwd>     //输入/输出系统使用的前置声明
#include <iostream>
#include <istream>     //基本输入流
#include <ostream>     //基本输出流
#include <queue>      //STL队列容器
#include <set>       //STL 集合容器
#include <sstream>    //基于字符串的流
#include <stack>      //STL堆栈容器    
#include <stdexcept>    //标准异常类
#include <streambuf>   //底层输入/输出支持
#include <string>     //字符串类
#include <utility>     //STL通用模板类
#include <vector>     //STL动态数组容器
#define ll long long
using namespace std;
#define rep(i,a,b) for(register int i=(a);i<=(b);i++)
#define dep(i,a,b) for(register int i=(a);i>=(b);i--)
//priority_queue<int,vector<int>,less<int> >q;
int dx[]= {-1,1,0,0,-1,-1,1,1};
int dy[]= {0,0,-1,1,-1,1,1,-1};
const int maxn = 200000+6;
const ll mod=1e9+7;
const ll inf=0x3f3f3f3f3f3f3f3fLL;
const int INF=99999999;
ll ans[20];
int main()
{
    int q;
    scanf("%d",&q);
    while(q--)
    {
        ll n,m;
        scanf("%lld %lld",&n,&m);
        ans[0]=0;
        rep(i,1,10)
        {
            ans[i]=ans[i-1]+i*m%10;
        }
        ll t=n/m;
        ll ans1=t/10*ans[10]+ans[t%10];
        printf("%lld\n",ans1);
    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值