QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#799118#9584. 顾影自怜LyniaTL 101ms17324kbC++233.3kb2024-12-04 22:25:152024-12-04 22:25:17

Judging History

你现在查看的是最新测评结果

  • [2024-12-04 22:25:17]
  • 评测
  • 测评结果:TL
  • 用时:101ms
  • 内存:17324kb
  • [2024-12-04 22:25:15]
  • 提交

answer

///////////        
//                   //      //
//              ////////////////////
//                   //      //
//                 
///////////

//          
//          
//           //     //    ////////     /\     /////////
//           //     //   //      //          //       //
//            ////////   //      //    //    //       //
//                  //   //      //    //    //       //
//////////   ////////    //      //    //     /////////////

#pragma GCC optimize(3,"Ofast","inline")
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <cstring>
#include <cmath>
#include <list>
#include <stack>
#include <array>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <random>
#include <numeric>
#include <functional>
#include <optional>
//#include <Windows.h>

using namespace std;

#define fa(i,op,n) for (int i = op; i <= n; i++)
#define fb(j,op,n) for (int j = op; j >= n; j--)
#define pb push_back
#define HashMap unordered_map
#define HashSet unordered_set
#define var auto
#define all(i) i.begin(), i.end()
#define all1(i) i.begin() + 1,i.end()
#define endl '\n'
#define px first
#define py second

using VI = vector<int>;
using VL = vector<long long>;
using ll = long long;
using ull = unsigned long long;
using db = double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T1, class T2>
ostream& operator<<(ostream& out, const pair<T1, T2>& p) {
	out << '(' << p.first << ", " << p.second << ')';
	return out;
}

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& ve) {
	for (T i : ve)
		out << i << ' ';
	return out;
}

template<class T1, class T2>
ostream& operator<<(ostream& out, const map<T1, T2>& mp) {
	for (auto i : mp)
		out << i << '\n';
	return out;
}

template<typename ...T>
bool _debug(T... a) {
	((cout << a << ' '), ...);
	cout << endl;
	return -1;
}

const int INF = 0x3f3f3f3f;
const ll LNF = 0x3f3f3f3f3f3f3f3f;
int dx[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };
int dy[8] = { 0, 0, 1, -1, 1, -1, -1, 1 };

//#include "Lynia.h"
namespace MyTools
{
	template <typename T>
	class Math;

	template <const int T>
	class ModInt;

}

namespace MT = MyTools;
using Math = MT::Math<ll>;
#define geo MT::Geo

const int mod = 1e9 + 7;
using mint = MT::ModInt<mod>;

const int N = 1e6 + 10;

void solve(int CASE)
{
	int n, k; cin >> n >> k;
	var a = vector<int>(n + 1);
	fa(i, 1, n)cin >> a[i];
	var dp = vector<int>(n + 1);
	var g = map<int, vector<int>>(); // a[i] 的下标表
	var st = stack<int>();
	fa(i, 1, n) {
		g[a[i]].pb(i);

		while (st.size() and a[st.top()] <= a[i])st.pop();

		int last = 0;
		if (st.size() and a[st.top()] > a[i]) {
			// 出现过比自己大的
			dp[i] = dp[st.top()];
			last = st.top();
		}

		int id = g[a[i]].size() - k;
		if (id >= 0 and g[a[i]][id] > last) {
			ll cnt = g[a[i]][id] - last;
			dp[i] += cnt;
		}

		st.push(i);
	}
	ll ans = 0;
	fa(i, 1, n) {
		//cout << dp[i] << ' ';
		ans += dp[i];
	}//cout << endl;

	cout << ans << endl;
	return;
}

int main()
{
	//SetConsoleOutputCP(CP_UTF8);
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int _ = 1;
	cin >> _;
	fa(i, 1, _)solve(i);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3576kb

input:

2
5 2
1 3 3 2 2
4 3
1 4 2 1

output:

7
0

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 38ms
memory: 17324kb

input:

1
1000000 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

500000500000

result:

ok single line: '500000500000'

Test #3:

score: 0
Accepted
time: 101ms
memory: 3584kb

input:

158921
1 1
1
2 1
1 1
2 2
1 1
2 1
1 2
2 2
1 2
2 1
2 1
2 2
2 1
2 1
2 2
2 2
2 2
3 1
1 1 1
3 2
1 1 1
3 3
1 1 1
3 1
1 1 2
3 2
1 1 2
3 3
1 1 2
3 1
1 1 3
3 2
1 1 3
3 3
1 1 3
3 1
1 2 1
3 2
1 2 1
3 3
1 2 1
3 1
1 2 2
3 2
1 2 2
3 3
1 2 2
3 1
1 2 3
3 2
1 2 3
3 3
1 2 3
3 1
1 3 1
3 2
1 3 1
3 3
1 3 1
3 1
1 3 2
3 2...

output:

1
3
1
3
0
3
0
3
1
6
3
1
6
1
0
6
1
0
6
0
0
6
2
0
6
0
0
6
0
0
6
0
0
6
2
0
6
1
0
6
1
0
6
0
0
6
2
0
6
3
1
6
1
0
6
0
0
6
0
0
6
2
0
6
1
0
6
0
0
6
1
0
6
0
0
6
1
0
6
1
0
6
2
0
6
2
0
6
3
1
10
6
3
1
10
3
1
0
10
3
1
0
10
3
1
0
10
1
0
0
10
4
0
0
10
1
0
0
10
1
0
0
10
1
0
0
10
1
0
0
10
4
0
0
10
1
0
0
10
1
0
0
10
...

result:

ok 158921 lines

Test #4:

score: 0
Accepted
time: 55ms
memory: 15256kb

input:

1
1000000 1000
1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 100...

output:

498003996002

result:

ok single line: '498003996002'

Test #5:

score: -100
Time Limit Exceeded

input:

24
217838 1
11125 61539 156386 82530 15545 110745 20051 71328 216682 107717 24565 71482 196259 23920 79507 74383 81434 99615 50571 31499 93241 126374 205674 57290 166999 83044 89340 72667 55001 143151 30341 98608 191197 96249 176106 113045 116438 34417 92531 200248 38119 106697 24629 117110 129552 1...

output:

23726806041
1590954891
782239681
139362697540
3608208775
205782590
1992948
1449
78
2701
6
1
720
4660
34
9
91
21
1
18
3
10
1
1

result: