QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#153452#6405. BarkleyaestheticWA 54ms4164kbC++143.3kb2023-08-30 02:39:522023-08-30 02:39:53

Judging History

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

  • [2023-08-30 02:39:53]
  • 评测
  • 测评结果:WA
  • 用时:54ms
  • 内存:4164kb
  • [2023-08-30 02:39:52]
  • 提交

answer

#include "bits/stdc++.h"
#define endl '\n'
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());
using namespace std;
// #define int long long
 
#define dbg_loc() cerr << __PRETTY_FUNCTION__ << " : " << __LINE__ << "\n"
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p){ 
	return os << '(' << p.first << ", " << p.second << ')'; 
}
template<typename T_container,typename T=typename enable_if<!is_same<T_container,string>::value, typename T_container::value_type>::type> 
ostream& operator<<(ostream &os, const T_container &v){ 
	os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; 
}
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T){ 
	cerr << ' ' << H; 
	dbg_out(T...); 
}
#define LOCAL
#define LOCAL
#ifdef LOCAL 
#define dbg(...) cerr<<"(" << #__VA_ARGS__<<"):" , dbg_out(__VA_ARGS__) , cerr << endl
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
ll mod = (1000000007LL);
inline ll Mod(ll a, ll b){return (a%b);}
inline ll poww(ll a, ll b){ll res = 1;while (b > 0){if(b & 1) res = (res * a)%mod;a = (a * a)%mod;b >>= 1;}return res;}
ll gcd (ll a, ll b) { while (b) { a %= b,swap(a, b);}return a;}
void read(vector<int> &w, int n){w.resize(n);for(int i = 0; i < n; i++) cin>>w[i];}
void print(vector<int> &w){for(int i =0; i < sz(w); i++){if(i == sz(w) - 1) cout<<w[i]<<"\n";else cout<<w[i]<<" ";}}
 
///CUIDADO COM MAXN
#define N 100020 // 1E6
 
ll dp[N*10][30];
int n, q;
vector<ll> v;
inline void build(){
  for(int i = 0; i < n; i++) dp[i][0] = v[i];
  for(int j = 1; j <= 19; j++)
      for(int i = 0; i < n; i++)
           dp[i][j] = gcd(dp[i][j - 1], dp[ i + (1<<(j - 1)) ][j - 1]);
}

inline ll query(int l, int r){
	if(l == r) return v[l];
	int exp = 31-__builtin_clz(r-l);
	return gcd(dp[l][exp], dp[r - (1<<exp) + 1][exp]);
}

map<pair<int, ll>, int> mapa;
int prox(int i, ll x){
	if(mapa.find({i, x}) != mapa.end()) return mapa[{i, x}];
	int ini = i+1, fim = sz(v) - 1, mid, best = sz(v);
	while(fim>=ini){
		mid=(ini+fim)/2;
		ll d = query(i,mid);
		if(d != x) best=mid,fim=mid-1;
		else ini=mid+1;
	}
	return mapa[{i,x}] = best;
}
 
map< pair<int, ll>, ll> vis;

ll solve(int i, ll x, int l, int r, int k){
	if(i > r){
		if(k == 0) return x;
		return -1;
	}
	if(vis.find({i,x})  != vis.end()) return vis[{i, x}];

	if(k == 0){
		return gcd(x,query(i, r));
	}
	// se eu for manter o x, tento remover o proximo
	ll d = gcd(v[i],x);
	ll A = solve(prox(i, x), d,l,r,k);

	//remove o i
	ll B = solve(i + 1, x, l, r, k-1);

	return  vis[{i,x}] = max(A, B);
}

void solve_case(){
	cin>>n>>q;
	v.resize(n);
	for(int i=0;i < n;i++) cin>>v[i];
	build();

	while(q--){
		int l, r, k;
		cin>>l>>r>>k;
		--l, --r;
		vis.clear();
		cout<<solve(l,0,l,r,k)<<"\n";
	}
 
}
 
int32_t main(){
	ios::sync_with_stdio(false); cin.tie(0);
	
	int test_case=1;
	// cin>>test_case;
	while(test_case--){
		solve_case();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 4
3 2 6 4
1 3 1
2 4 1
1 4 2
1 4 3

output:

3
2
3
6

result:

ok 4 number(s): "3 2 3 6"

Test #2:

score: 0
Accepted
time: 6ms
memory: 3732kb

input:

100 10000
7 25 33 17 13 33 24 29 11 1 3 19 2 20 33 23 14 24 15 12 3 1 5 13 6 35 15 21 10 34 31 19 7 33 17 26 26 1 19 21 31 5 29 20 18 32 19 18 19 31 11 26 6 19 2 26 23 1 4 2 31 21 29 30 1 14 20 23 14 32 4 34 13 29 5 26 24 29 28 5 26 26 21 19 2 33 2 31 30 3 23 24 26 32 36 21 21 11 5 9
56 57 1
90 97 1...

output:

26
1
1
1
1
1
1
1
31
1
1
1
1
1
26
1
1
1
1
1
1
29
1
1
1
1
1
1
4
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
2
1
1
1
21
1
1
1
1
1
19
1
1
1
21
1
1
1
1
1
1
1
1
1
1
1
1
1
3
1
1
1
1
1
1
1
1
1
1
4
1
1
1
1
1
3
1
2
1
26
1
1
1
1
1
1
1
7
1
1
1
33
1
1
1
1
1
1
2
1
26
1
1
1
2
1
1
1
1
1
1
26
1
1
1
1
31
1
1
2
1
4
29
1
2
1
1...

result:

ok 10000 numbers

Test #3:

score: -100
Wrong Answer
time: 54ms
memory: 4164kb

input:

1000 66666
25 21 18 19 9 34 16 7 36 2 8 10 25 15 34 9 1 34 6 19 20 20 1 16 10 6 10 1 30 34 6 15 15 11 9 4 34 36 27 17 2 2 19 10 4 22 15 16 22 36 27 26 20 23 29 16 27 14 3 31 32 16 5 5 31 13 27 5 17 23 20 19 13 22 30 14 25 13 7 16 10 6 1 6 3 5 36 1 33 22 31 26 28 3 14 14 2 31 35 7 19 30 36 5 3 14 14 ...

output:

1
2
1
1
1
1
1
1
1
1
1
3
1
2
1
1
1
1
1
1
1
1
2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
17
1
1
1
20
1
1
1
7
1
1
1
1
1
1
1
1
3
1
1
1
1
1
1
7
1
2
15
1
3
1
2
1
1
3
4
1
1
1
1
1
31
1
1
1
2
1
1
1
1
27
3
1
1
1
1
4
10
1
1
1
1
17
1
1
1
2
1
1
2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
1
1
1
8
1
1
17
1
2
1
1
1
30
1
25
1
35
1...

result:

wrong answer 1223rd numbers differ - expected: '30', found: '25'